From: Derick Rethans Date: Sun, 9 Dec 2007 16:54:52 +0000 (+0000) Subject: - MFH: Fixed Bug #42272 (var_export() incorrectly escapes char(0)). X-Git-Tag: RELEASE_1_3_1~532 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fdafd5cf81a97f1e7f277ad2250cecee09e13c22;p=php - MFH: Fixed Bug #42272 (var_export() incorrectly escapes char(0)). --- diff --git a/ext/standard/tests/general_functions/bug42272.phpt b/ext/standard/tests/general_functions/bug42272.phpt new file mode 100644 index 0000000000..5a455d7257 --- /dev/null +++ b/ext/standard/tests/general_functions/bug42272.phpt @@ -0,0 +1,11 @@ +--TEST-- +Bug #42272: var_export() incorrectly escapes char(0). +--FILE-- + +--EXPECT-- +'' . "\0" . '' +'a' . "\0" . 'b' diff --git a/ext/standard/tests/general_functions/var_export-locale.phpt b/ext/standard/tests/general_functions/var_export-locale.phpt index 6d2df85424..81896550bc 100644 --- a/ext/standard/tests/general_functions/var_export-locale.phpt +++ b/ext/standard/tests/general_functions/var_export-locale.phpt @@ -572,9 +572,9 @@ string(3) "' '" Iteration 12 -'\000' -'\000' -string(6) "'\000'" +'' . "\0" . '' +'' . "\0" . '' +string(14) "'' . "\0" . ''" Iteration 13 diff --git a/ext/standard/tests/general_functions/var_export.phpt b/ext/standard/tests/general_functions/var_export.phpt index 2a99c5bd8a..b5cc886e4b 100644 --- a/ext/standard/tests/general_functions/var_export.phpt +++ b/ext/standard/tests/general_functions/var_export.phpt @@ -565,9 +565,9 @@ string(3) "' '" Iteration 12 -'\000' -'\000' -string(6) "'\000'" +'' . "\0" . '' +'' . "\0" . '' +string(14) "'' . "\0" . ''" Iteration 13 diff --git a/ext/standard/tests/strings/bug37262.phpt b/ext/standard/tests/strings/bug37262.phpt index 474251a816..6fe2d9f379 100644 --- a/ext/standard/tests/strings/bug37262.phpt +++ b/ext/standard/tests/strings/bug37262.phpt @@ -6,4 +6,4 @@ $func = create_function('$a', 'return $a;'); var_export($func); ?> --EXPECT-- -'\000lambda_1' +'' . "\0" . 'lambda_1' diff --git a/ext/standard/var.c b/ext/standard/var.c index cf9fd0145d..c416e8af98 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -389,8 +389,8 @@ static int php_object_element_export(zval **zv, int num_args, va_list args, zend PHPAPI void php_var_export(zval **struc, int level TSRMLS_DC) /* {{{ */ { HashTable *myht; - char* tmp_str; - int tmp_len; + char *tmp_str, *tmp_str2; + int tmp_len, tmp_len2; char *class_name; zend_uint class_name_len; @@ -408,11 +408,13 @@ PHPAPI void php_var_export(zval **struc, int level TSRMLS_DC) /* {{{ */ php_printf("%.*H", (int) EG(precision), Z_DVAL_PP(struc)); break; case IS_STRING: - tmp_str = php_addcslashes(Z_STRVAL_PP(struc), Z_STRLEN_PP(struc), &tmp_len, 0, "'\\\0", 3 TSRMLS_CC); + tmp_str = php_addcslashes(Z_STRVAL_PP(struc), Z_STRLEN_PP(struc), &tmp_len, 0, "'\\", 2 TSRMLS_CC); + tmp_str2 = php_str_to_str_ex(tmp_str, tmp_len, "\0", 1, "' . \"\\0\" . '", 12, &tmp_len2, 0, NULL); PUTS ("'"); - PHPWRITE(tmp_str, tmp_len); + PHPWRITE(tmp_str2, tmp_len2); PUTS ("'"); - efree (tmp_str); + efree(tmp_str2); + efree(tmp_str); break; case IS_ARRAY: myht = Z_ARRVAL_PP(struc);