From 1b4570b79fa9810b171d3fb074c405f2f429ecad Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 20 Jun 2016 18:43:07 +0200 Subject: [PATCH 1/4] Fix bug #71936 (Segmentation fault destroying HTTP_RAW_POST_DATA) --- NEWS | 4 ++++ main/php_content_types.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/NEWS b/NEWS index 91d190db1ee..06e5bb7a806 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,10 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2016, PHP 5.6.24 +- Core: + . Fix bug #71936 (Segmentation fault destroying HTTP_RAW_POST_DATA). + (mike dot laspina at gmail dot com, Remi) + - bz2: . Fix bug #72447 (Type Confusion in php_bz2_filter_create()). (gogil at stealien dot com). diff --git a/main/php_content_types.c b/main/php_content_types.c index abc796db3c5..6d7d24dab8b 100644 --- a/main/php_content_types.c +++ b/main/php_content_types.c @@ -70,6 +70,9 @@ SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader) (unsigned long) length, INT_MAX); length = INT_MAX; } + if (!data) { + data = STR_EMPTY_ALLOC(); + } SET_VAR_STRINGL("HTTP_RAW_POST_DATA", data, length); sapi_module.sapi_error(E_DEPRECATED, From 297502609068724ae4222c6e9baefe2b26165063 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Mon, 20 Jun 2016 20:20:32 +0200 Subject: [PATCH 2/4] update NEWS --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index 03b56eab2a6..b2b7654d78e 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,7 @@ PHP NEWS finishes). (Nikita) . Fixed bug #69489 (tempnam() should raise notice if falling back to temp dir). (Laruence, Anatol) + . Fixed UTF-8 and long path support on Windows. (Anatol) - GD: . Fixed bug #43475 (Thick styled lines have scrambled patterns). (cmb) From f0d1cca6729f2593900af10d6aa324b7eedfe0c3 Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Sun, 29 May 2016 20:15:16 +0100 Subject: [PATCH 3/4] Use empty keys instead of _empty_ in json decoding --- NEWS | 3 +++ UPGRADING | 2 ++ ext/json/json_encoder.c | 2 +- ext/json/json_parser.tab.c | 5 +---- ext/json/json_parser.y | 5 +---- ext/json/tests/001.phpt | 6 +++--- ext/json/tests/pass001.1_64bit.phpt | 6 +++--- ext/json/tests/pass001.phpt | 6 +++--- 8 files changed, 17 insertions(+), 18 deletions(-) diff --git a/NEWS b/NEWS index b2b7654d78e..01a63142ebf 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,9 @@ PHP NEWS . Fixed bug #53640 (XBM images require width to be multiple of 8). (cmb) . Fixed bug #64641 (imagefilledpolygon doesn't draw horizontal line). (cmb) +- JSON + . Implemented FR #46600 ("_empty_" key in objects). (Jakub Zelenka) + - Mbstring: . Fixed bug #72405 (mb_ereg_replace - mbc_to_code (oniguruma) - oob read access). (Laruence) diff --git a/UPGRADING b/UPGRADING index 1e3532deaa7..69406a3c352 100644 --- a/UPGRADING +++ b/UPGRADING @@ -46,6 +46,8 @@ PHP 7.1 UPGRADE NOTES the notice level only. - JSON: + . An empty key is decoded as an empty property name instead of using _empty_ + property name when decoding object to stdClass. . When calling json_encode with JSON_UNESCAPED_UNICODE option, U+2028 and U+2029 are escaped. diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c index 62df1028471..f944b888c76 100644 --- a/ext/json/json_encoder.c +++ b/ext/json/json_encoder.c @@ -169,7 +169,7 @@ static void php_json_encode_array(smart_str *buf, zval *val, int options) /* {{{ php_json_encode(buf, data, options); } else if (r == PHP_JSON_OUTPUT_OBJECT) { if (key) { - if (ZSTR_VAL(key)[0] == '\0' && Z_TYPE_P(val) == IS_OBJECT) { + if (ZSTR_VAL(key)[0] == '\0' && ZSTR_LEN(key) > 0 && Z_TYPE_P(val) == IS_OBJECT) { /* Skip protected and private members. */ if (tmp_ht && ZEND_HASH_APPLY_PROTECTION(tmp_ht)) { ZEND_HASH_DEC_APPLY_COUNT(tmp_ht); diff --git a/ext/json/json_parser.tab.c b/ext/json/json_parser.tab.c index 02002d681b2..862912c4ec7 100644 --- a/ext/json/json_parser.tab.c +++ b/ext/json/json_parser.tab.c @@ -1881,10 +1881,7 @@ static int php_json_parser_object_update(php_json_parser *parser, zval *object, zend_symtable_update(Z_ARRVAL_P(object), key, zvalue); } else { zval zkey; - if (ZSTR_LEN(key) == 0) { - zend_string_release(key); - key = zend_string_init("_empty_", sizeof("_empty_") - 1, 0); - } else if (ZSTR_VAL(key)[0] == '\0') { + if (ZSTR_LEN(key) > 0 && ZSTR_VAL(key)[0] == '\0') { parser->scanner.errcode = PHP_JSON_ERROR_INVALID_PROPERTY_NAME; zend_string_release(key); zval_dtor(zvalue); diff --git a/ext/json/json_parser.y b/ext/json/json_parser.y index fafe75cbf34..43d941b56c4 100644 --- a/ext/json/json_parser.y +++ b/ext/json/json_parser.y @@ -273,10 +273,7 @@ static int php_json_parser_object_update(php_json_parser *parser, zval *object, zend_symtable_update(Z_ARRVAL_P(object), key, zvalue); } else { zval zkey; - if (ZSTR_LEN(key) == 0) { - zend_string_release(key); - key = zend_string_init("_empty_", sizeof("_empty_") - 1, 0); - } else if (ZSTR_VAL(key)[0] == '\0') { + if (ZSTR_LEN(key) > 0 && ZSTR_VAL(key)[0] == '\0') { parser->scanner.errcode = PHP_JSON_ERROR_INVALID_PROPERTY_NAME; zend_string_release(key); zval_dtor(zvalue); diff --git a/ext/json/tests/001.phpt b/ext/json/tests/001.phpt index 02d43c42439..e908b44349f 100644 --- a/ext/json/tests/001.phpt +++ b/ext/json/tests/001.phpt @@ -53,16 +53,16 @@ object(stdClass)#%d (1) { } } object(stdClass)#%d (1) { - ["_empty_"]=> + [""]=> object(stdClass)#%d (1) { ["foo"]=> string(0) "" } } object(stdClass)#%d (1) { - ["_empty_"]=> + [""]=> object(stdClass)#%d (1) { - ["_empty_"]=> + [""]=> string(0) "" } } diff --git a/ext/json/tests/pass001.1_64bit.phpt b/ext/json/tests/pass001.1_64bit.phpt index e6666d15993..3970fa434e2 100644 --- a/ext/json/tests/pass001.1_64bit.phpt +++ b/ext/json/tests/pass001.1_64bit.phpt @@ -204,7 +204,7 @@ array(14) { float(1.23456789E-13) ["E"]=> float(1.23456789E+34) - ["_empty_"]=> + [""]=> float(INF) ["E no ."]=> float(4000000000000) @@ -527,7 +527,7 @@ array(14) { string(7) "rosebud" } ENCODE: FROM OBJECT -["JSON Test Pattern pass1",{"object with 1 member":["array with 1 element"]},{},[],-42,true,false,null,{"integer":1234567890,"real":-9876.54321,"e":1.23456789e-13,"E":1.23456789e+34,"_empty_":0,"E no .":4000000000000,"zero":0,"one":1,"space":" ","quote":"\"","backslash":"\\","controls":"\b\f\n\r\t","slash":"\/ & \/","alpha":"abcdefghijklmnopqrstuvwyz","ALPHA":"ABCDEFGHIJKLMNOPQRSTUVWYZ","digit":"0123456789","special":"`1~!@#$%^&*()_+-={':[,]}|;.<\/>?","hex":"\u0123\u4567\u89ab\ucdef\uabcd\uef4a","unicode":"\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8","\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8":"\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8","empty_string":"","true":true,"false":false,"null":null,"array":[],"object":{},"123":{"456":{"abc":{"789":"def","012":[1,2,"5",500],"ghi":[1,2,"five",50,"sixty"]}}},"address":"50 St. James Street","url":"http:\/\/www.JSON.org\/","comment":"\/\/ \/* *\/":" "," s p a c e d ":[1,2,3,4,5,6,7],"compact":[1,2,3,4,5,6,7],"jsontext":"{\"object with 1 member\":[\"array with 1 element\"]}","quotes":"" \" %22 0x22 034 "","\/\\\"\ucafe\ubabe\uab98\ufcde\ubcda\uef4a\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',.\/<>?":"A key can be any string"},0.5,98.6,99.44,1066,"rosebud"] +["JSON Test Pattern pass1",{"object with 1 member":["array with 1 element"]},{},[],-42,true,false,null,{"integer":1234567890,"real":-9876.54321,"e":1.23456789e-13,"E":1.23456789e+34,"":0,"E no .":4000000000000,"zero":0,"one":1,"space":" ","quote":"\"","backslash":"\\","controls":"\b\f\n\r\t","slash":"\/ & \/","alpha":"abcdefghijklmnopqrstuvwyz","ALPHA":"ABCDEFGHIJKLMNOPQRSTUVWYZ","digit":"0123456789","special":"`1~!@#$%^&*()_+-={':[,]}|;.<\/>?","hex":"\u0123\u4567\u89ab\ucdef\uabcd\uef4a","unicode":"\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8","\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8":"\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8","empty_string":"","true":true,"false":false,"null":null,"array":[],"object":{},"123":{"456":{"abc":{"789":"def","012":[1,2,"5",500],"ghi":[1,2,"five",50,"sixty"]}}},"address":"50 St. James Street","url":"http:\/\/www.JSON.org\/","comment":"\/\/ \/* *\/":" "," s p a c e d ":[1,2,3,4,5,6,7],"compact":[1,2,3,4,5,6,7],"jsontext":"{\"object with 1 member\":[\"array with 1 element\"]}","quotes":"" \" %22 0x22 034 "","\/\\\"\ucafe\ubabe\uab98\ufcde\ubcda\uef4a\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',.\/<>?":"A key can be any string"},0.5,98.6,99.44,1066,"rosebud"] ENCODE: FROM ARRAY ["JSON Test Pattern pass1",{"object with 1 member":["array with 1 element"]},[],[],-42,true,false,null,{"integer":1234567890,"real":-9876.54321,"e":1.23456789e-13,"E":1.23456789e+34,"":0,"E no .":4000000000000,"zero":0,"one":1,"space":" ","quote":"\"","backslash":"\\","controls":"\b\f\n\r\t","slash":"\/ & \/","alpha":"abcdefghijklmnopqrstuvwyz","ALPHA":"ABCDEFGHIJKLMNOPQRSTUVWYZ","digit":"0123456789","special":"`1~!@#$%^&*()_+-={':[,]}|;.<\/>?","hex":"\u0123\u4567\u89ab\ucdef\uabcd\uef4a","unicode":"\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8","\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8":"\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8","empty_string":"","true":true,"false":false,"null":null,"array":[],"object":[],"123":{"456":{"abc":{"789":"def","012":[1,2,"5",500],"ghi":[1,2,"five",50,"sixty"]}}},"address":"50 St. James Street","url":"http:\/\/www.JSON.org\/","comment":"\/\/ \/* *\/":" "," s p a c e d ":[1,2,3,4,5,6,7],"compact":[1,2,3,4,5,6,7],"jsontext":"{\"object with 1 member\":[\"array with 1 element\"]}","quotes":"" \" %22 0x22 034 "","\/\\\"\ucafe\ubabe\uab98\ufcde\ubcda\uef4a\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',.\/<>?":"A key can be any string"},0.5,98.6,99.44,1066,"rosebud"] DECODE AGAIN: AS OBJECT @@ -566,7 +566,7 @@ array(14) { float(1.23456789E-13) ["E"]=> float(1.23456789E+34) - ["_empty_"]=> + [""]=> int(0) ["E no ."]=> int(4000000000000) diff --git a/ext/json/tests/pass001.phpt b/ext/json/tests/pass001.phpt index ffe7c61f01d..948929d5a58 100644 --- a/ext/json/tests/pass001.phpt +++ b/ext/json/tests/pass001.phpt @@ -188,7 +188,7 @@ array(14) { float(1.23456789E-13) ["E"]=> float(1.23456789E+34) - ["_empty_"]=> + [""]=> float(INF) ["zero"]=> int(0) @@ -425,7 +425,7 @@ array(14) { string(7) "rosebud" } ENCODE: FROM OBJECT -["JSON Test Pattern pass1",{"object with 1 member":["array with 1 element"]},{},[],-42,true,false,null,{"integer":1234567890,"real":-9876.54321,"e":1.23456789e-13,"E":1.23456789e+34,"_empty_":0,"zero":0,"one":1,"space":" ","quote":"\"","backslash":"\\","controls":"\b\f\n\r\t","slash":"\/ & \/","alpha":"abcdefghijklmnopqrstuvwyz","ALPHA":"ABCDEFGHIJKLMNOPQRSTUVWYZ","digit":"0123456789","special":"`1~!@#$%^&*()_+-={':[,]}|;.<\/>?","hex":"\u0123\u4567\u89ab\ucdef\uabcd\uef4a","true":true,"false":false,"null":null,"array":[],"object":{},"address":"50 St. James Street","url":"http:\/\/www.JSON.org\/","comment":"\/\/ \/* *\/":" "," s p a c e d ":[1,2,3,4,5,6,7],"compact":[1,2,3,4,5,6,7],"jsontext":"{\"object with 1 member\":[\"array with 1 element\"]}","quotes":"" \" %22 0x22 034 "","\/\\\"\ucafe\ubabe\uab98\ufcde\ubcda\uef4a\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',.\/<>?":"A key can be any string"},0.5,98.6,99.44,1066,"rosebud"] +["JSON Test Pattern pass1",{"object with 1 member":["array with 1 element"]},{},[],-42,true,false,null,{"integer":1234567890,"real":-9876.54321,"e":1.23456789e-13,"E":1.23456789e+34,"":0,"zero":0,"one":1,"space":" ","quote":"\"","backslash":"\\","controls":"\b\f\n\r\t","slash":"\/ & \/","alpha":"abcdefghijklmnopqrstuvwyz","ALPHA":"ABCDEFGHIJKLMNOPQRSTUVWYZ","digit":"0123456789","special":"`1~!@#$%^&*()_+-={':[,]}|;.<\/>?","hex":"\u0123\u4567\u89ab\ucdef\uabcd\uef4a","true":true,"false":false,"null":null,"array":[],"object":{},"address":"50 St. James Street","url":"http:\/\/www.JSON.org\/","comment":"\/\/ \/* *\/":" "," s p a c e d ":[1,2,3,4,5,6,7],"compact":[1,2,3,4,5,6,7],"jsontext":"{\"object with 1 member\":[\"array with 1 element\"]}","quotes":"" \" %22 0x22 034 "","\/\\\"\ucafe\ubabe\uab98\ufcde\ubcda\uef4a\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',.\/<>?":"A key can be any string"},0.5,98.6,99.44,1066,"rosebud"] ENCODE: FROM ARRAY ["JSON Test Pattern pass1",{"object with 1 member":["array with 1 element"]},[],[],-42,true,false,null,{"integer":1234567890,"real":-9876.54321,"e":1.23456789e-13,"E":1.23456789e+34,"":0,"zero":0,"one":1,"space":" ","quote":"\"","backslash":"\\","controls":"\b\f\n\r\t","slash":"\/ & \/","alpha":"abcdefghijklmnopqrstuvwyz","ALPHA":"ABCDEFGHIJKLMNOPQRSTUVWYZ","digit":"0123456789","special":"`1~!@#$%^&*()_+-={':[,]}|;.<\/>?","hex":"\u0123\u4567\u89ab\ucdef\uabcd\uef4a","true":true,"false":false,"null":null,"array":[],"object":[],"address":"50 St. James Street","url":"http:\/\/www.JSON.org\/","comment":"\/\/ \/* *\/":" "," s p a c e d ":[1,2,3,4,5,6,7],"compact":[1,2,3,4,5,6,7],"jsontext":"{\"object with 1 member\":[\"array with 1 element\"]}","quotes":"" \" %22 0x22 034 "","\/\\\"\ucafe\ubabe\uab98\ufcde\ubcda\uef4a\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',.\/<>?":"A key can be any string"},0.5,98.6,99.44,1066,"rosebud"] DECODE AGAIN: AS OBJECT @@ -464,7 +464,7 @@ array(14) { float(1.23456789E-13) ["E"]=> float(1.23456789E+34) - ["_empty_"]=> + [""]=> int(0) ["zero"]=> int(0) From 7cc1b0016301d713d6566cf3ee77a8b27e41abb5 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 20 Jun 2016 22:18:46 +0300 Subject: [PATCH 4/4] Improved support for zend-signals. --- sapi/cgi/cgi_main.c | 2 ++ sapi/cli/php_cli_server.c | 1 + 2 files changed, 3 insertions(+) diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index e3398e03e05..01ab2ad0982 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -2066,6 +2066,7 @@ consult the installation file that came with this distribution, or visit \n\ sigaction(SIGTERM, &old_term, 0); sigaction(SIGQUIT, &old_quit, 0); sigaction(SIGINT, &old_int, 0); + zend_signal_init(); break; case -1: perror("php (pre-forking)"); @@ -2105,6 +2106,7 @@ consult the installation file that came with this distribution, or visit \n\ } } else { parent = 0; + zend_signal_init(); } #else diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index a9d4a533b36..650f4887522 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -2548,6 +2548,7 @@ int do_cli_server(int argc, char **argv) /* {{{ */ #if defined(HAVE_SIGNAL_H) && defined(SIGINT) signal(SIGINT, php_cli_server_sigint_handler); + zend_signal_init(); #endif php_cli_server_do_event_loop(&server); php_cli_server_dtor(&server);