iliaa Thu Dec 7 01:41:29 2006 UTC Modified files: /php-src/ext/posix posix.c config.m4 Log: MFB: Fixed bug #39754 (Some POSIX extension functions not thread safe). http://cvs.php.net/viewvc.cgi/php-src/ext/posix/posix.c?r1=1.81&r2=1.82&diff_format=u Index: php-src/ext/posix/posix.c diff -u php-src/ext/posix/posix.c:1.81 php-src/ext/posix/posix.c:1.82 --- php-src/ext/posix/posix.c:1.81 Thu Nov 30 00:35:27 2006 +++ php-src/ext/posix/posix.c Thu Dec 7 01:41:29 2006 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: posix.c,v 1.81 2006/11/30 00:35:27 iliaa Exp $ */ +/* $Id: posix.c,v 1.82 2006/12/07 01:41:29 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.81 $"); + php_info_print_table_row(2, "Revision", "$Revision: 1.82 $"); 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); } /* }}} */ @@ -803,22 +816,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 } /* }}} */ @@ -846,7 +878,6 @@ efree(grbuf); RETURN_FALSE; } - efree(grbuf); g = &_g; #else if (NULL == (g = getgrgid(gid))) { @@ -858,8 +889,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 } /* }}} */ @@ -886,23 +920,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 } /* }}} */ @@ -930,7 +982,6 @@ efree(pwbuf); RETURN_FALSE; } - efree(pwbuf); pw = &_pw; #else if (NULL == (pw = getpwuid(uid))) { @@ -942,8 +993,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.14&r2=1.15&diff_format=u Index: php-src/ext/posix/config.m4 diff -u php-src/ext/posix/config.m4:1.14 php-src/ext/posix/config.m4:1.15 --- php-src/ext/posix/config.m4:1.14 Thu Nov 30 16:48:27 2006 +++ php-src/ext/posix/config.m4 Thu Dec 7 01:41:29 2006 @@ -1,5 +1,5 @@ dnl -dnl $Id: config.m4,v 1.14 2006/11/30 16:48:27 iliaa Exp $ +dnl $Id: config.m4,v 1.15 2006/12/07 01:41:29 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
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php