iliaa           Thu Dec  7 01:41:19 2006 UTC

  Modified files:              (Branch: PHP_5_2)
    /php-src/ext/posix  posix.c config.m4 
    /php-src    NEWS 
  Log:
  Fixed bug #39754 (Some POSIX extension functions not thread safe).
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/posix/posix.c?r1=1.70.2.3.2.7&r2=1.70.2.3.2.8&diff_format=u
Index: php-src/ext/posix/posix.c
diff -u php-src/ext/posix/posix.c:1.70.2.3.2.7 
php-src/ext/posix/posix.c:1.70.2.3.2.8
--- php-src/ext/posix/posix.c:1.70.2.3.2.7      Thu Nov 30 00:35:15 2006
+++ php-src/ext/posix/posix.c   Thu Dec  7 01:41:18 2006
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: posix.c,v 1.70.2.3.2.7 2006/11/30 00:35:15 iliaa Exp $ */
+/* $Id: posix.c,v 1.70.2.3.2.8 2006/12/07 01:41:18 iliaa Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -147,7 +147,7 @@
 static PHP_MINFO_FUNCTION(posix)
 {
        php_info_print_table_start();
-       php_info_print_table_row(2, "Revision", "$Revision: 1.70.2.3.2.7 $");
+       php_info_print_table_row(2, "Revision", "$Revision: 1.70.2.3.2.8 $");
        php_info_print_table_end();
 }
 /* }}} */
@@ -555,6 +555,9 @@
        zval **z_fd;
        char *p;
        int fd;
+#if HAVE_TTYNAME_R
+       size_t buflen;
+#endif
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &z_fd) == 
FAILURE) {
                RETURN_FALSE;
@@ -570,12 +573,22 @@
                        convert_to_long_ex(z_fd);
                        fd = Z_LVAL_PP(z_fd);
        }
+#if HAVE_TTYNAME_R
+       buflen = sysconf(_SC_TTY_NAME_MAX);
+       p = emalloc(buflen);
 
+       if (ttyname_r(fd, p, buflen)) {
+               POSIX_G(last_error) = errno;
+               efree(p);
+               RETURN_FALSE;
+       }
+       RETURN_STRING(p, 0);
+#else
        if (NULL == (p = ttyname(fd))) {
                POSIX_G(last_error) = errno;
                RETURN_FALSE;
        }
-       
+#endif 
        RETURN_STRING(p, 1);
 }
 /* }}} */
@@ -809,22 +822,41 @@
        char *name;
        struct group *g;
        int name_len;
+#if HAVE_GETGRNAM_R
+       struct group gbuf;
+       int buflen;
+       char *buf;
+#endif
        
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, 
&name_len) == FAILURE) {
                RETURN_FALSE;
        }
 
+#if HAVE_GETGRNAM_R
+       buflen = sysconf(_SC_GETGR_R_SIZE_MAX);
+       buf = emalloc(buflen);
+       g = &gbuf;
+
+       if (getgrnam_r(name, g, buf, buflen, &g) || g == NULL) {
+               POSIX_G(last_error) = errno;
+               efree(buf);
+               RETURN_FALSE;
+       }
+#else
        if (NULL == (g = getgrnam(name))) {
                POSIX_G(last_error) = errno;
                RETURN_FALSE;
        }
-       
+#endif
        array_init(return_value);
 
        if (!php_posix_group_to_array(g, return_value)) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to convert 
posix group to array");
-               RETURN_FALSE;
+               RETVAL_FALSE;
        }
+#if HAVE_GETGRNAM_R
+       efree(buf);
+#endif
 }
 /* }}} */
 
@@ -852,7 +884,6 @@
                efree(grbuf);
                RETURN_FALSE;
        }
-       efree(grbuf);
        g = &_g;
 #else
        if (NULL == (g = getgrgid(gid))) {
@@ -864,8 +895,11 @@
 
        if (!php_posix_group_to_array(g, return_value)) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to convert 
posix group struct to array");
-               RETURN_FALSE;
+               RETVAL_FALSE;
        }
+#ifdef HAVE_GETGRGID_R
+       efree(grbuf);
+#endif
 }
 /* }}} */
 
@@ -892,23 +926,41 @@
        struct passwd *pw;
        char *name;
        int name_len;
-       
+#ifdef HAVE_GETPWNAM_R
+       struct passwd pwbuf;
+       int buflen;
+       char *buf;
+#endif
+
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, 
&name_len) == FAILURE) {
                RETURN_FALSE;
        }
 
+#ifdef HAVE_GETPWNAM_R
+       buflen = sysconf(_SC_GETPW_R_SIZE_MAX);
+       buf = emalloc(buflen);
+       pw = &pwbuf;
+
+       if (getpwnam_r(name, pw, buf, buflen, &pw) || pw == NULL) {
+               efree(buf);
+               POSIX_G(last_error) = errno;
+               RETURN_FALSE;
+       }
+#else
        if (NULL == (pw = getpwnam(name))) {
                POSIX_G(last_error) = errno;
                RETURN_FALSE;
        }
-       
+#endif 
        array_init(return_value);
 
        if (!php_posix_passwd_to_array(pw, return_value)) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to convert 
posix passwd struct to array");
-               RETURN_FALSE;
+               RETVAL_FALSE;
        }
-
+#ifdef HAVE_GETPWNAM_R
+       efree(buf);
+#endif
 }
 /* }}} */
 
@@ -936,7 +988,6 @@
                efree(pwbuf);
                RETURN_FALSE;
        }
-       efree(pwbuf);
        pw = &_pw;
 #else
        if (NULL == (pw = getpwuid(uid))) {
@@ -948,8 +999,11 @@
 
        if (!php_posix_passwd_to_array(pw, return_value)) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to convert 
posix passwd struct to array");
-               RETURN_FALSE;
+               RETVAL_FALSE;
        }
+#ifdef HAVE_GETPWUID_R
+       efree(pwbuf);
+#endif
 }
 /* }}} */
 
http://cvs.php.net/viewvc.cgi/php-src/ext/posix/config.m4?r1=1.12.4.2&r2=1.12.4.3&diff_format=u
Index: php-src/ext/posix/config.m4
diff -u php-src/ext/posix/config.m4:1.12.4.2 
php-src/ext/posix/config.m4:1.12.4.3
--- php-src/ext/posix/config.m4:1.12.4.2        Thu Nov 30 16:48:03 2006
+++ php-src/ext/posix/config.m4 Thu Dec  7 01:41:18 2006
@@ -1,5 +1,5 @@
 dnl
-dnl $Id: config.m4,v 1.12.4.2 2006/11/30 16:48:03 iliaa Exp $
+dnl $Id: config.m4,v 1.12.4.3 2006/12/07 01:41:18 iliaa Exp $
 dnl
 
 PHP_ARG_ENABLE(posix,whether to enable POSIX-like functions,
@@ -11,5 +11,5 @@
 
   AC_CHECK_HEADERS(sys/mkdev.h)
 
-  AC_CHECK_FUNCS(seteuid setegid setsid getsid setpgid getpgid ctermid mkfifo 
mknod getrlimit getlogin getgroups makedev initgroups getpwuid_r getgrgid_r)
+  AC_CHECK_FUNCS(seteuid setegid setsid getsid setpgid getpgid ctermid mkfifo 
mknod getrlimit getlogin getgroups makedev initgroups getpwuid_r getgrgid_r 
ttyname_r)
 fi
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.408&r2=1.2027.2.547.2.409&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.408 php-src/NEWS:1.2027.2.547.2.409
--- php-src/NEWS:1.2027.2.547.2.408     Wed Dec  6 21:20:39 2006
+++ php-src/NEWS        Thu Dec  7 01:41:18 2006
@@ -49,6 +49,8 @@
 - Fixed FastCGI impersonation for persistent connections on Windows. (Dmitry)
 - Fixed wrong signature initialization in imagepng (Takeshi Abe)
 - Added optimization for imageline with horizontal and vertial lines (Pierre)
+- Fixed bug #39754 (Some POSIX extension functions not thread safe).
+  (Ilia, wharmby at uk dot ibm dot com)
 - Fixed bug #39724 (Broken build due to spl/filter usage of pcre extension).
   (Tony, Ilia)
 - Fixed bug #39718 (possible crash if assert.callback is set in ini). (Ilia)

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to