From: Ilia Alshanetsky Date: Sat, 29 Nov 2003 04:43:06 +0000 (+0000) Subject: Fixed bug #26458 (var_dump(), var_export(), debug_zval_dump() not binary X-Git-Tag: php-5.0.0b3RC1~547 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=91052eb93beb3324acc6df35f4f71f92d4e82c89;p=php Fixed bug #26458 (var_dump(), var_export(), debug_zval_dump() not binary safe for array keys). --- diff --git a/ext/standard/tests/array/007.phpt b/ext/standard/tests/array/007.phpt index 753aced821..6f2fd98e30 100644 --- a/ext/standard/tests/array/007.phpt +++ b/ext/standard/tests/array/007.phpt @@ -309,23 +309,17 @@ $b=array ( var_dump(array_udiff_uassoc($a, $b, "comp_func_cr", "comp_func")); array(3) { ["0.1"]=> - object(cr)#%d (%d) { - [""]=> - int(9) + object(cr)#1 (2) { ["public_member"]=> int(9) } ["0.5"]=> - object(cr)#%d (%d) { - [""]=> - int(12) + object(cr)#2 (2) { ["public_member"]=> int(12) } [0]=> - object(cr)#%d (%d) { - [""]=> - int(23) + object(cr)#3 (2) { ["public_member"]=> int(23) } @@ -387,23 +381,17 @@ $b=array ( var_dump(array_udiff_uassoc($a, $b, array("cr", "comp_func_cr"), "comp_func")); array(3) { ["0.1"]=> - object(cr)#%d (%d) { - [""]=> - int(9) + object(cr)#1 (2) { ["public_member"]=> int(9) } ["0.5"]=> - object(cr)#%d (%d) { - [""]=> - int(12) + object(cr)#2 (2) { ["public_member"]=> int(12) } [0]=> - object(cr)#%d (%d) { - [""]=> - int(23) + object(cr)#3 (2) { ["public_member"]=> int(23) } @@ -465,37 +453,27 @@ $b=array ( var_dump(array_diff_assoc($a, $b)); array(5) { ["0.1"]=> - object(cr)#%d (%d) { - [""]=> - int(9) + object(cr)#1 (2) { ["public_member"]=> int(9) } ["0.5"]=> - object(cr)#%d (%d) { - [""]=> - int(12) + object(cr)#2 (2) { ["public_member"]=> int(12) } [0]=> - object(cr)#%d (%d) { - [""]=> - int(23) + object(cr)#3 (2) { ["public_member"]=> int(23) } [1]=> - object(cr)#%d (%d) { - [""]=> - int(4) + object(cr)#4 (2) { ["public_member"]=> int(4) } [2]=> - object(cr)#%d (%d) { - [""]=> - int(-15) + object(cr)#5 (2) { ["public_member"]=> int(-15) } @@ -557,16 +535,12 @@ $b=array ( var_dump(array_udiff($a, $b, "comp_func_cr")); array(2) { ["0.5"]=> - object(cr)#%d (%d) { - [""]=> - int(12) + object(cr)#2 (2) { ["public_member"]=> int(12) } [0]=> - object(cr)#%d (%d) { - [""]=> - int(23) + object(cr)#3 (2) { ["public_member"]=> int(23) } @@ -628,23 +602,17 @@ $b=array ( var_dump(array_udiff_assoc($a, $b, "comp_func_cr")); array(3) { ["0.1"]=> - object(cr)#%d (%d) { - [""]=> - int(9) + object(cr)#1 (2) { ["public_member"]=> int(9) } ["0.5"]=> - object(cr)#%d (%d) { - [""]=> - int(12) + object(cr)#2 (2) { ["public_member"]=> int(12) } [0]=> - object(cr)#%d (%d) { - [""]=> - int(23) + object(cr)#3 (2) { ["public_member"]=> int(23) } diff --git a/ext/standard/tests/array/array_intersect_1.phpt b/ext/standard/tests/array/array_intersect_1.phpt index 5a09d84d71..34b94833b0 100644 --- a/ext/standard/tests/array/array_intersect_1.phpt +++ b/ext/standard/tests/array/array_intersect_1.phpt @@ -204,23 +204,17 @@ $b=array ( var_dump(array_uintersect($a, $b, "comp_func_cr")); array(3) { ["0.1"]=> - object(cr)#%d (2) { - [""]=> - int(9) + object(cr)#1 (2) { ["public_member"]=> int(9) } [1]=> - object(cr)#%d (2) { - [""]=> - int(4) + object(cr)#4 (2) { ["public_member"]=> int(4) } [2]=> - object(cr)#%d (2) { - [""]=> - int(-15) + object(cr)#5 (2) { ["public_member"]=> int(-15) } @@ -343,16 +337,12 @@ $b=array ( var_dump(array_uintersect_assoc($a, $b, "comp_func_cr")); array(2) { [1]=> - object(cr)#%d (2) { - [""]=> - int(4) + object(cr)#4 (2) { ["public_member"]=> int(4) } [2]=> - object(cr)#%d (2) { - [""]=> - int(-15) + object(cr)#5 (2) { ["public_member"]=> int(-15) } @@ -475,16 +465,12 @@ $b=array ( var_dump(array_uintersect_uassoc($a, $b, "comp_func_cr", "comp_func")); array(2) { [1]=> - object(cr)#%d (2) { - [""]=> - int(4) + object(cr)#4 (2) { ["public_member"]=> int(4) } [2]=> - object(cr)#%d (2) { - [""]=> - int(-15) + object(cr)#5 (2) { ["public_member"]=> int(-15) } @@ -548,16 +534,12 @@ $b=array ( var_dump(array_uintersect_uassoc($a, $b, array("cr", "comp_func_cr"), "comp_func")); array(2) { [1]=> - object(cr)#%d (2) { - [""]=> - int(4) + object(cr)#4 (2) { ["public_member"]=> int(4) } [2]=> - object(cr)#%d (2) { - [""]=> - int(-15) + object(cr)#5 (2) { ["public_member"]=> int(-15) } diff --git a/ext/standard/tests/array/bug26458.phpt b/ext/standard/tests/array/bug26458.phpt new file mode 100644 index 0000000000..d24e1f151b Binary files /dev/null and b/ext/standard/tests/array/bug26458.phpt differ diff --git a/ext/standard/var.c b/ext/standard/var.c index a33c8da200..0358080cac 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -50,7 +50,15 @@ static int php_array_element_dump(zval **zv, int num_args, va_list args, zend_ha if (hash_key->nKeyLength==0) { /* numeric key */ php_printf("%*c[%ld]=>\n", level + 1, ' ', hash_key->h); } else { /* string key */ - php_printf("%*c[\"%s\"]=>\n", level + 1, ' ', hash_key->arKey); + if (va_arg(args, int) && hash_key->arKey[0] == '\0') { + /* XXX: perphaps when we are inside the class we should permit access to + * private & protected values + */ + return 0; + } + php_printf("%*c[\"", level + 1, ' '); + PHPWRITE(hash_key->arKey, hash_key->nKeyLength - 1); + php_printf("\"]=>\n"); } php_var_dump(zv, level + 2 TSRMLS_CC); return 0; @@ -107,7 +115,7 @@ PHPAPI void php_var_dump(zval **struc, int level TSRMLS_DC) efree(class_name); head_done: if (myht) { - zend_hash_apply_with_arguments(myht, (apply_func_args_t) php_array_element_dump, 1, level); + zend_hash_apply_with_arguments(myht, (apply_func_args_t) php_array_element_dump, 1, level, (Z_TYPE_PP(struc) == IS_ARRAY ? 0 : 1)); } if (level > 1) { php_printf("%*c", level-1, ' '); @@ -166,7 +174,15 @@ static int zval_array_element_dump(zval **zv, int num_args, va_list args, zend_h if (hash_key->nKeyLength==0) { /* numeric key */ php_printf("%*c[%ld]=>\n", level + 1, ' ', hash_key->h); } else { /* string key */ - php_printf("%*c[\"%s\"]=>\n", level + 1, ' ', hash_key->arKey); + /* XXX: perphaps when we are inside the class we should permit access to + * private & protected values + */ + if (va_arg(args, int) && hash_key->arKey[0] == '\0') { + return 0; + } + php_printf("%*c[\"", level + 1, ' '); + PHPWRITE(hash_key->arKey, hash_key->nKeyLength - 1); + php_printf("\"]=>\n"); } php_debug_zval_dump(zv, level + 2 TSRMLS_CC); return 0; @@ -213,7 +229,7 @@ PHPAPI void php_debug_zval_dump(zval **struc, int level TSRMLS_DC) efree(class_name); head_done: if (myht) { - zend_hash_apply_with_arguments(myht, (apply_func_args_t) zval_array_element_dump, 1, level); + zend_hash_apply_with_arguments(myht, (apply_func_args_t) zval_array_element_dump, 1, level, (Z_TYPE_PP(struc) == IS_ARRAY ? 0 : 1)); } if (level > 1) { php_printf("%*c", level-1, ' '); @@ -271,11 +287,20 @@ static int php_array_element_export(zval **zv, int num_args, va_list args, zend_ if (hash_key->nKeyLength==0) { /* numeric key */ php_printf("%*c%ld => ", level + 1, ' ', hash_key->h); } else { /* string key */ - char *key; - int key_len; - key = php_addcslashes(hash_key->arKey, hash_key->nKeyLength - 1, &key_len, 0, "'\\", 2 TSRMLS_CC); - php_printf("%*c'%s' => ", level + 1, ' ', key); - efree(key); + /* XXX: perphaps when we are inside the class we should permit access to + * private & protected values + */ + if (va_arg(args, int) && hash_key->arKey[0] == '\0') { + return 0; + } else { + char *key; + int key_len; + key = php_addcslashes(hash_key->arKey, hash_key->nKeyLength - 1, &key_len, 0, "'\\", 2 TSRMLS_CC); + php_printf("%*c'", level + 1, ' '); + PHPWRITE(key, key_len); + php_printf("' => "); + efree(key); + } } php_var_export(zv, level + 2 TSRMLS_CC); PUTS (",\n"); @@ -331,7 +356,7 @@ PHPAPI void php_var_export(zval **struc, int level TSRMLS_DC) php_printf("\n%*c", level - 1, ' '); } PUTS ("array (\n"); - zend_hash_apply_with_arguments(myht, (apply_func_args_t) php_array_element_export, 1, level); + zend_hash_apply_with_arguments(myht, (apply_func_args_t) php_array_element_export, 1, level, (Z_TYPE_PP(struc) == IS_ARRAY ? 0 : 1)); if (level > 1) { php_printf("%*c", level - 1, ' '); }