From 180b25ef78c352b0807523a493dd2ff8c269b554 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Thu, 10 Mar 2022 19:21:06 +0100 Subject: [PATCH 1/3] Fix GH-8068: mysqli_fetch_object creates inaccessible properties When fetching into objects, we need to create object style hash tables, i.e. where numeric column names are stored as string keys instead of integer keys. Instead of the slightly more efficient alternative to create the desired hash table in the first place, we go for the more readable implementation and convert the array style hash table using `zend_symtable_to_proptable()`. --- ext/mysqli/mysqli.c | 8 +++++--- ext/mysqli/tests/gh8068.phpt | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 ext/mysqli/tests/gh8068.phpt diff --git a/ext/mysqli/mysqli.c b/ext/mysqli/mysqli.c index 852eb02c6bc90..165893b32f4a1 100644 --- a/ext/mysqli/mysqli.c +++ b/ext/mysqli/mysqli.c @@ -1198,11 +1198,13 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags ZVAL_COPY_VALUE(&dataset, return_value); object_init_ex(return_value, ce); + HashTable *prop_table = zend_symtable_to_proptable(Z_ARR(dataset)); + zval_ptr_dtor(&dataset); if (!ce->default_properties_count && !ce->__set) { - Z_OBJ_P(return_value)->properties = Z_ARR(dataset); + Z_OBJ_P(return_value)->properties = prop_table; } else { - zend_merge_properties(return_value, Z_ARRVAL(dataset)); - zval_ptr_dtor(&dataset); + zend_merge_properties(return_value, prop_table); + zend_array_release(prop_table); } if (ce->constructor) { diff --git a/ext/mysqli/tests/gh8068.phpt b/ext/mysqli/tests/gh8068.phpt new file mode 100644 index 0000000000000..6bab6bc0add09 --- /dev/null +++ b/ext/mysqli/tests/gh8068.phpt @@ -0,0 +1,25 @@ +--TEST-- +GH-8068 (mysqli_fetch_object creates inaccessible properties) +--SKIPIF-- + +--FILE-- +query('SELECT 42'); +$obj = $res->fetch_object(); +var_dump( + $obj, + $obj->{42} +); +?> +--EXPECT-- +object(stdClass)#4 (1) { + ["42"]=> + string(2) "42" +} +string(2) "42" From ceb21df93712fb3fb4f5028316a1d235dcfb0c9c Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Fri, 11 Mar 2022 13:02:15 +0100 Subject: [PATCH 2/3] Update ext/mysqli/tests/gh8068.phpt Co-authored-by: Kamil Tekiela --- ext/mysqli/tests/gh8068.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/mysqli/tests/gh8068.phpt b/ext/mysqli/tests/gh8068.phpt index 6bab6bc0add09..ad4faa531b623 100644 --- a/ext/mysqli/tests/gh8068.phpt +++ b/ext/mysqli/tests/gh8068.phpt @@ -7,7 +7,7 @@ require_once('skipifconnectfailure.inc'); ?> --FILE-- query('SELECT 42'); From 9b5656910f45da1a8cf5056da6c406b31b3ebc3e Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Fri, 11 Mar 2022 13:02:20 +0100 Subject: [PATCH 3/3] Update ext/mysqli/tests/gh8068.phpt Co-authored-by: Kamil Tekiela --- ext/mysqli/tests/gh8068.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/mysqli/tests/gh8068.phpt b/ext/mysqli/tests/gh8068.phpt index ad4faa531b623..db6ce230b936c 100644 --- a/ext/mysqli/tests/gh8068.phpt +++ b/ext/mysqli/tests/gh8068.phpt @@ -2,8 +2,8 @@ GH-8068 (mysqli_fetch_object creates inaccessible properties) --SKIPIF-- --FILE--