From 5c11525f48dada193793f7ac0cdace5a65dcfce7 Mon Sep 17 00:00:00 2001 From: Xenira <1288524+Xenira@users.noreply.github.com> Date: Mon, 21 Oct 2024 23:33:14 +0200 Subject: [PATCH] fix(globals): correctly fetch `$_REQUEST` super global Refs: #331 --- allowed_bindings.rs | 6 ++++++ src/zend/globals.rs | 34 ++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/allowed_bindings.rs b/allowed_bindings.rs index c6a593808..350b9e857 100644 --- a/allowed_bindings.rs +++ b/allowed_bindings.rs @@ -39,6 +39,7 @@ bind! { _zend_new_array, _zval_struct__bindgen_ty_1, _zval_struct__bindgen_ty_2, + _zend_known_string_id, // ext_php_rs_executor_globals, // ext_php_rs_php_build_id, // ext_php_rs_zend_object_alloc, @@ -84,6 +85,8 @@ bind! { zend_execute_data, zend_function_entry, zend_hash_clean, + zend_hash_find, + zend_hash_find_known_hash, zend_hash_index_del, zend_hash_index_find, zend_hash_index_update, @@ -95,6 +98,7 @@ bind! { zend_is_callable, zend_is_identical, zend_is_iterable, + zend_known_strings, zend_long, zend_lookup_class_ex, zend_module_entry, @@ -137,6 +141,7 @@ bind! { E_RECOVERABLE_ERROR, E_DEPRECATED, E_USER_DEPRECATED, + EG, HT_MIN_SIZE, IS_ARRAY, IS_ARRAY_EX, @@ -224,6 +229,7 @@ bind! { ZEND_MODULE_API_NO, ZEND_PROPERTY_EXISTS, ZEND_PROPERTY_ISSET, + ZEND_STR_AUTOGLOBAL_REQUEST, Z_TYPE_FLAGS_SHIFT, _IS_BOOL, _ZEND_IS_VARIADIC_BIT, diff --git a/src/zend/globals.rs b/src/zend/globals.rs index 21ba29c8c..7418a709e 100644 --- a/src/zend/globals.rs +++ b/src/zend/globals.rs @@ -13,12 +13,13 @@ use crate::exception::PhpResult; #[cfg(php82)] use crate::ffi::zend_atomic_bool_store; use crate::ffi::{ - _sapi_module_struct, _zend_executor_globals, ext_php_rs_executor_globals, - ext_php_rs_file_globals, ext_php_rs_process_globals, ext_php_rs_sapi_globals, - ext_php_rs_sapi_module, php_core_globals, php_file_globals, sapi_globals_struct, - sapi_header_struct, sapi_headers_struct, sapi_request_info, zend_ini_entry, - zend_is_auto_global, TRACK_VARS_COOKIE, TRACK_VARS_ENV, TRACK_VARS_FILES, TRACK_VARS_GET, - TRACK_VARS_POST, TRACK_VARS_SERVER, + _sapi_module_struct, _zend_executor_globals, _zend_known_string_id_ZEND_STR_AUTOGLOBAL_REQUEST, + executor_globals, ext_php_rs_executor_globals, ext_php_rs_file_globals, + ext_php_rs_process_globals, ext_php_rs_sapi_globals, ext_php_rs_sapi_module, php_core_globals, + php_file_globals, sapi_globals_struct, sapi_header_struct, sapi_headers_struct, + sapi_request_info, zend_hash_find, zend_hash_find_known_hash, zend_ini_entry, + zend_is_auto_global, zend_known_strings, TRACK_VARS_COOKIE, TRACK_VARS_ENV, TRACK_VARS_FILES, + TRACK_VARS_GET, TRACK_VARS_POST, TRACK_VARS_SERVER, }; use crate::types::{ZendHashTable, ZendObject, ZendStr}; @@ -283,15 +284,20 @@ impl ProcessGlobals { } /// Get the HTTP Request variables. Equivalent of $_REQUEST. - /// - /// # Panics - /// There is an outstanding issue with the implementation of this function. - /// Untill resolved, this function will allways panic. - /// - /// - - /// - pub fn http_request_vars(&self) -> &ZendHashTable { - todo!("$_REQUEST super global was erroneously fetched from http_globals which resulted in an out-of-bounds access. A new implementation is needed."); + unsafe { + let key = + *zend_known_strings.add(_zend_known_string_id_ZEND_STR_AUTOGLOBAL_REQUEST as usize); + println!("{:?}", *key); + println!("{:#?}", executor_globals.symbol_table); + let hash = zend_hash_find_known_hash(&executor_globals.symbol_table, key); + println!("{:?}", hash); + if hash.is_null() { + panic!("Could not find the request hash"); + } + (*hash).array().expect("Type is not a ZendArray") + } + // self.http_globals[TRACK_VARS_REQUEST as usize] // .array() // .expect("Type is not a ZendArray")