php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68861 chown does not work when php is compiling with ZTS
Submitted: 2015-01-20 13:06 UTC Modified: -
Votes:9
Avg. Score:4.0 ± 0.7
Reproduced:9 of 9 (100.0%)
Same Version:3 (33.3%)
Same OS:9 (100.0%)
From: lg at efficientip dot com Assigned:
Status: Open Package: Filesystem function related
PHP Version: 5.6.4 OS: FreeBSD
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
24 + 6 = ?
Subscribe to this entry?

 
 [2015-01-20 13:06 UTC] lg at efficientip dot com
Description:
------------
chown() does not work when PHP is compiling with ZTS on FreeBSD, In fact sysconf(_SC_GETGR_R_SIZE_MAX) may return -1 if there is no hard limit on the size of the buffer needed to store all the groups returned.


Test script:
---------------
<?php

exec('touch /tmp/test')
chown('/tmp/test', 'www');

?>


Expected result:
----------------
root:/tmp # php test.php
root:/tmp # ls -l /tmp/test
-rw-r--r--  1 www  wheel  0 Jan 20 13:19 /tmp/test


Actual result:
--------------
root:/tmp # php test.php

Warning: chown(): Unable to find uid for www in /tmp/test.php on line 4

root:/tmp # ls -l /tmp/test
-rw-r--r--  1 root  wheel  0 Jan 20 13:19 /tmp/test


Patches

php_get_uid_by_name.patch (last revision 2015-01-20 13:07 UTC) by lg at efficientip dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-19 18:03 UTC] php at nearlyfreespeech dot net
This issue is still present on PHP 7.2 with FreeBSD 11.2.

The code for php_get_gid_by_name() needs the same fix as well, otherwise chgrp() gets the same result.

diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c
index e730b5ae8d..deb0600d9f 100644
--- a/ext/standard/filestat.c
+++ b/ext/standard/filestat.c
@@ -303,6 +303,8 @@ PHPAPI int php_get_gid_by_name(const char *name, gid_t *gid)
                long grbuflen = sysconf(_SC_GETGR_R_SIZE_MAX);
                char *grbuf;

+               if ( -1 == grbuflen )
+                       grbuflen = 1024;
                if (grbuflen < 1) {
                        return FAILURE;
                }
@@ -439,6 +441,8 @@ PHPAPI uid_t php_get_uid_by_name(const char *name, uid_t *uid)
                long pwbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
                char *pwbuf;

+               if ( -1 == pwbuflen )
+                       pwbuflen = 1024;
                if (pwbuflen < 1) {
                        return FAILURE;
                }
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Fri Nov 16 03:01:26 2018 UTC