iliaa Fri Nov 28 23:43:07 2003 EDT
Added files:
/php-src/ext/standard/tests/array bug26458.phpt
Modified files:
/php-src/ext/standard var.c
/php-src/ext/standard/tests/array array_intersect_1.phpt 007.phpt
Log:
Fixed bug #26458 (var_dump(), var_export(), debug_zval_dump() not binary
safe for array keys).
Index: php-src/ext/standard/var.c
diff -u php-src/ext/standard/var.c:1.176 php-src/ext/standard/var.c:1.177
--- php-src/ext/standard/var.c:1.176 Fri Nov 28 10:42:58 2003
+++ php-src/ext/standard/var.c Fri Nov 28 23:43:06 2003
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: var.c,v 1.176 2003/11/28 15:42:58 wez Exp $ */
+/* $Id: var.c,v 1.177 2003/11/29 04:43:06 iliaa Exp $ */
/* {{{ includes
@@ -50,7 +50,15 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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, ' ');
}
Index: php-src/ext/standard/tests/array/array_intersect_1.phpt
diff -u php-src/ext/standard/tests/array/array_intersect_1.phpt:1.1
php-src/ext/standard/tests/array/array_intersect_1.phpt:1.2
--- php-src/ext/standard/tests/array/array_intersect_1.phpt:1.1 Thu Oct 9 04:10:39
2003
+++ php-src/ext/standard/tests/array/array_intersect_1.phpt Fri Nov 28 23:43:06
2003
@@ -204,23 +204,17 @@
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 @@
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 @@
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 @@
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)
}
Index: php-src/ext/standard/tests/array/007.phpt
diff -u php-src/ext/standard/tests/array/007.phpt:1.5
php-src/ext/standard/tests/array/007.phpt:1.6
--- php-src/ext/standard/tests/array/007.phpt:1.5 Tue Sep 30 11:22:33 2003
+++ php-src/ext/standard/tests/array/007.phpt Fri Nov 28 23:43:06 2003
@@ -309,23 +309,17 @@
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 @@
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 @@
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 @@
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 @@
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)
}
Index: php-src/ext/standard/tests/array/bug26458.phpt
+++ php-src/ext/standard/tests/array/bug26458.phpt
--TEST--
Bug #26458 (var_dump(), var_export() & debug_zval_dump() are not binary safe for array
keys)
--FILE--
<?php
$test = array("A\x00B" => "Hello world");
var_dump($test);
var_export($test);
debug_zval_dump($test);
?>
--EXPECT--
array(1) {
["AB"]=>
string(11) "Hello world"
}
array (
'AB' => 'Hello world',
)array(1) refcount(2){
["AB"]=>
string(11) "Hello world" refcount(1)
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php