lbarnaud Tue Oct 21 16:44:00 2008 UTC Modified files: (Branch: PHP_5_2) /php-src NEWS /php-src/sapi/cgi cgi_main.c fastcgi.c fastcgi.h Log: MFH: Fixed FCGI_GET_VALUES requests (fixes #45522) http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.1268&r2=1.2027.2.547.2.1269&diff_format=u Index: php-src/NEWS diff -u php-src/NEWS:1.2027.2.547.2.1268 php-src/NEWS:1.2027.2.547.2.1269 --- php-src/NEWS:1.2027.2.547.2.1268 Mon Oct 20 23:23:45 2008 +++ php-src/NEWS Tue Oct 21 16:43:59 2008 @@ -24,7 +24,9 @@ (chsc at peytz dot dk, Felipe) - Fixed bug #46026 (bzip2.decompress/zlib.inflate filter tries to decompress after end of stream). (Keisial at gmail dot com, Greg) -- Fixed buf #45722 (mb_check_encoding() crashes). (Moriyoshi) +- Fixed bug #45722 (mb_check_encoding() crashes). (Moriyoshi) +- Fixed bug #45522 (FCGI_GET_VALUES request does not return supplied values). + (Arnaud) - Fixed bug #44251, #41125 (PDO + quote() + prepare() can result in segfault). (tsteiner at nerdclub dot net) - Fixed bug #43723 (SOAP not sent properly from client for <choice>). (Dmitry) http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.267.2.15.2.62&r2=1.267.2.15.2.63&diff_format=u Index: php-src/sapi/cgi/cgi_main.c diff -u php-src/sapi/cgi/cgi_main.c:1.267.2.15.2.62 php-src/sapi/cgi/cgi_main.c:1.267.2.15.2.63 --- php-src/sapi/cgi/cgi_main.c:1.267.2.15.2.62 Fri Oct 17 01:32:59 2008 +++ php-src/sapi/cgi/cgi_main.c Tue Oct 21 16:43:59 2008 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: cgi_main.c,v 1.267.2.15.2.62 2008/10/17 01:32:59 iliaa Exp $ */ +/* $Id: cgi_main.c,v 1.267.2.15.2.63 2008/10/21 16:43:59 lbarnaud Exp $ */ #include "php.h" #include "php_globals.h" @@ -1545,11 +1545,18 @@ #ifndef PHP_WIN32 /* Pre-fork, if required */ if (getenv("PHP_FCGI_CHILDREN")) { - children = atoi(getenv("PHP_FCGI_CHILDREN")); + char * children_str = getenv("PHP_FCGI_CHILDREN"); + children = atoi(children_str); if (children < 0) { fprintf(stderr, "PHP_FCGI_CHILDREN is not valid\n"); return FAILURE; } + fcgi_set_mgmt_var("FCGI_MAX_CONNS", sizeof("FCGI_MAX_CONNS")-1, children_str, strlen(children_str)); + /* This is the number of concurrent requests, equals FCGI_MAX_CONNS */ + fcgi_set_mgmt_var("FCGI_MAX_REQS", sizeof("FCGI_MAX_REQS")-1, children_str, strlen(children_str)); + } else { + fcgi_set_mgmt_var("FCGI_MAX_CONNS", sizeof("FCGI_MAX_CONNS")-1, "1", sizeof("1")-1); + fcgi_set_mgmt_var("FCGI_MAX_REQS", sizeof("FCGI_MAX_REQS")-1, "1", sizeof("1")-1); } if (children) { http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/fastcgi.c?r1=1.4.2.13.2.31&r2=1.4.2.13.2.32&diff_format=u Index: php-src/sapi/cgi/fastcgi.c diff -u php-src/sapi/cgi/fastcgi.c:1.4.2.13.2.31 php-src/sapi/cgi/fastcgi.c:1.4.2.13.2.32 --- php-src/sapi/cgi/fastcgi.c:1.4.2.13.2.31 Tue Jul 15 13:10:07 2008 +++ php-src/sapi/cgi/fastcgi.c Tue Oct 21 16:43:59 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: fastcgi.c,v 1.4.2.13.2.31 2008/07/15 13:10:07 dmitry Exp $ */ +/* $Id: fastcgi.c,v 1.4.2.13.2.32 2008/10/21 16:43:59 lbarnaud Exp $ */ #include "php.h" #include "fastcgi.h" @@ -133,18 +133,7 @@ struct sockaddr_in sa_inet; } sa_t; -typedef struct _fcgi_mgmt_rec { - char* name; - char name_len; - char val; -} fcgi_mgmt_rec; - -static const fcgi_mgmt_rec fcgi_mgmt_vars[] = { - {"FCGI_MAX_CONNS", sizeof("FCGI_MAX_CONNS")-1, 1}, - {"FCGI_MAX_REQS", sizeof("FCGI_MAX_REQS")-1, 1}, - {"FCGI_MPXS_CONNS", sizeof("FCGI_MPXS_CONNS")-1, 0} -}; - +static HashTable fcgi_mgmt_vars; static int is_initialized = 0; static int is_fastcgi = 0; @@ -194,6 +183,8 @@ int fcgi_init(void) { if (!is_initialized) { + zend_hash_init(&fcgi_mgmt_vars, 0, NULL, fcgi_free_mgmt_var_cb, 1); + fcgi_set_mgmt_var("FCGI_MPXS_CONNS", sizeof("FCGI_MPXS_CONNS")-1, "0", sizeof("0")-1); #ifdef _WIN32 # if 0 /* TODO: Support for TCP sockets */ @@ -260,6 +251,9 @@ void fcgi_shutdown(void) { + if (is_initialized) { + zend_hash_destroy(&fcgi_mgmt_vars); + } is_fastcgi = 0; } @@ -748,8 +742,13 @@ padding = hdr.paddingLength; } } else if (hdr.type == FCGI_GET_VALUES) { - int j; unsigned char *p = buf + sizeof(fcgi_header); + HashPosition pos; + char * str_index; + uint str_length; + ulong num_index; + int key_type; + zval ** value; if (safe_read(req, buf, len+padding) != len+padding) { req->keep = 0; @@ -761,11 +760,41 @@ return 0; } - for (j = 0; j < sizeof(fcgi_mgmt_vars)/sizeof(fcgi_mgmt_vars[0]); j++) { - if (zend_hash_exists(&req->env, fcgi_mgmt_vars[j].name, fcgi_mgmt_vars[j].name_len+1) == 0) { - sprintf((char*)p, "%c%c%s%c", fcgi_mgmt_vars[j].name_len, 1, fcgi_mgmt_vars[j].name, fcgi_mgmt_vars[j].val); - p += fcgi_mgmt_vars[j].name_len + 3; + zend_hash_internal_pointer_reset_ex(&req->env, &pos); + while ((key_type = zend_hash_get_current_key_ex(&req->env, &str_index, &str_length, &num_index, 0, &pos)) != HASH_KEY_NON_EXISTANT) { + int zlen; + zend_hash_move_forward_ex(&req->env, &pos); + if (key_type != HASH_KEY_IS_STRING) { + continue; + } + if (zend_hash_find(&fcgi_mgmt_vars, str_index, str_length, (void**) &value) != SUCCESS) { + continue; + } + --str_length; + zlen = Z_STRLEN_PP(value); + if ((p + 4 + 4 + str_length + zlen) >= (buf + sizeof(buf))) { + break; } + if (str_length < 0x80) { + *p++ = str_length; + } else { + *p++ = ((str_length >> 24) & 0xff) | 0x80; + *p++ = (str_length >> 16) & 0xff; + *p++ = (str_length >> 8) & 0xff; + *p++ = str_length & 0xff; + } + if (zlen < 0x80) { + *p++ = zlen; + } else { + *p++ = ((zlen >> 24) & 0xff) | 0x80; + *p++ = (zlen >> 16) & 0xff; + *p++ = (zlen >> 8) & 0xff; + *p++ = zlen & 0xff; + } + memcpy(p, str_index, str_length); + p += str_length; + memcpy(p, Z_STRVAL_PP(value), zlen); + p += zlen; } len = p - buf - sizeof(fcgi_header); len += fcgi_make_header((fcgi_header*)buf, FCGI_GET_VALUES_RESULT, 0, len); @@ -1224,6 +1253,23 @@ } #endif +void fcgi_set_mgmt_var(char * name, size_t name_len, const char * value, size_t value_len) +{ + zval * zvalue; + zvalue = pemalloc(sizeof(*zvalue), 1); + Z_TYPE_P(zvalue) = IS_STRING; + Z_STRVAL_P(zvalue) = pestrndup(value, value_len, 1); + Z_STRLEN_P(zvalue) = value_len; + zend_hash_add(&fcgi_mgmt_vars, name, name_len + 1, &zvalue, sizeof(zvalue), NULL); +} + +void fcgi_free_mgmt_var_cb(void * ptr) +{ + zval ** var = (zval **)ptr; + pefree(Z_STRVAL_PP(var), 1); + pefree(*var, 1); +} + /* * Local variables: * tab-width: 4 http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/fastcgi.h?r1=1.2.2.4.2.6&r2=1.2.2.4.2.7&diff_format=u Index: php-src/sapi/cgi/fastcgi.h diff -u php-src/sapi/cgi/fastcgi.h:1.2.2.4.2.6 php-src/sapi/cgi/fastcgi.h:1.2.2.4.2.7 --- php-src/sapi/cgi/fastcgi.h:1.2.2.4.2.6 Mon Dec 31 07:20:16 2007 +++ php-src/sapi/cgi/fastcgi.h Tue Oct 21 16:43:59 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: fastcgi.h,v 1.2.2.4.2.6 2007/12/31 07:20:16 sebastian Exp $ */ +/* $Id: fastcgi.h,v 1.2.2.4.2.7 2008/10/21 16:43:59 lbarnaud Exp $ */ /* FastCGI protocol */ @@ -131,6 +131,10 @@ #ifdef PHP_WIN32 void fcgi_impersonate(void); #endif + +void fcgi_set_mgmt_var(char * name, size_t name_len, const char * value, size_t value_len); +void fcgi_free_mgmt_var_cb(void * ptr); + /* * Local variables: * tab-width: 4
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php