summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2006-11-29 23:34:49 +0000
committerIlia Alshanetsky <iliaa@php.net>2006-11-29 23:34:49 +0000
commit466d9ba00ae7459a4afe9c0131df356b44f16e7b (patch)
treeae86f790a93a50d029f78a09ee76b1aa0f46e5e7
parent4cc29fef5c9fefb6f8565f6f5a4da7233db68703 (diff)
downloadphp-git-466d9ba00ae7459a4afe9c0131df356b44f16e7b.tar.gz
Fixed bug #39648 (Implementation of PHP functions chown() and chgrp() are
not thread safe).
-rw-r--r--NEWS2
-rw-r--r--configure.in2
-rw-r--r--ext/standard/filestat.c44
3 files changed, 40 insertions, 8 deletions
diff --git a/NEWS b/NEWS
index 017c57a4a8..7ef7301986 100644
--- a/NEWS
+++ b/NEWS
@@ -55,6 +55,8 @@ PHP NEWS
after closeCursor()). (Ilia, Tony)
- Fixed bug #39653 (ext/dba doesn't check for db-4.5 and db-4.4 when db4
support is enabled). (Tony)
+- Fixed bug #39648 (Implementation of PHP functions chown() and chgrp() are not
+ thread safe). (Ilia, wharmby at uk dot ibm dot com)
- Fixed bug #39623 (thread safety fixes on *nix for putenv() & mime_magic).
(Ilia, wharmby at uk dot ibm dot com)
- Fixed bug #39621 (str_replace() is not binary safe on strings with equal
diff --git a/configure.in b/configure.in
index 750544feac..cb779e7919 100644
--- a/configure.in
+++ b/configure.in
@@ -480,6 +480,8 @@ getservbyport \
getrusage \
gettimeofday \
gmtime_r \
+getpwnam_r \
+getgrnam_r \
grantpt \
inet_ntoa \
inet_ntop \
diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c
index 126ace89f9..5e98cc412e 100644
--- a/ext/standard/filestat.c
+++ b/ext/standard/filestat.c
@@ -356,7 +356,6 @@ static void php_do_chgrp(INTERNAL_FUNCTION_PARAMETERS, int do_lchgrp)
{
zval **filename, **group;
gid_t gid;
- struct group *gr=NULL;
int ret;
if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &filename, &group)==FAILURE) {
@@ -364,13 +363,28 @@ static void php_do_chgrp(INTERNAL_FUNCTION_PARAMETERS, int do_lchgrp)
}
convert_to_string_ex(filename);
if (Z_TYPE_PP(group) == IS_STRING) {
- gr = getgrnam(Z_STRVAL_PP(group));
+#if HAVE_GETGRNAM_R
+ struct group gr;
+ struct group *retgrptr;
+ int grbuflen = sysconf(_SC_GETGR_R_SIZE_MAX);
+ char *grbuf = emalloc(grbuflen);
+
+ if (getgrnam_r(Z_STRVAL_PP(group), &gr, grbuf, grbuflen, &retgrptr) != 0 || retgrptr == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find gid for %s", Z_STRVAL_PP(group));
+ efree(grbuf);
+ RETURN_FALSE;
+ }
+ efree(grbuf);
+ gid = gr.gr_gid;
+#else
+ struct group *gr = getgrnam(Z_STRVAL_PP(group));
+
if (!gr) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find gid for %s",
- Z_STRVAL_PP(group));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find gid for %s", Z_STRVAL_PP(group));
RETURN_FALSE;
}
gid = gr->gr_gid;
+#endif
} else {
convert_to_long_ex(group);
gid = Z_LVAL_PP(group);
@@ -434,20 +448,34 @@ static void php_do_chown(INTERNAL_FUNCTION_PARAMETERS, int do_lchown)
zval **filename, **user;
int ret;
uid_t uid;
- struct passwd *pw = NULL;
if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &filename, &user)==FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string_ex(filename);
if (Z_TYPE_PP(user) == IS_STRING) {
- pw = getpwnam(Z_STRVAL_PP(user));
+#ifdef HAVE_GETPWNAM_R
+ struct passwd pw;
+ struct passwd *retpwptr = NULL;
+ int pwbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
+ char *pwbuf = emalloc(pwbuflen);
+
+ if (getpwnam_r(Z_STRVAL_PP(user), &pw, pwbuf, pwbuflen, &retpwptr) != 0 || retpwptr == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find uid for %s", Z_STRVAL_PP(user));
+ efree(pwbuf);
+ RETURN_FALSE;
+ }
+ efree(pwbuf);
+ uid = pw.pw_uid;
+#else
+ struct passwd *pw = getpwnam(Z_STRVAL_PP(user));
+
if (!pw) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find uid for %s",
- Z_STRVAL_PP(user));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find uid for %s", Z_STRVAL_PP(user));
RETURN_FALSE;
}
uid = pw->pw_uid;
+#endif
} else {
convert_to_long_ex(user);
uid = Z_LVAL_PP(user);