Skip to content

Commit

Permalink
fix(globals): correctly fetch $_REQUEST super global
Browse files Browse the repository at this point in the history
Refs: #331
  • Loading branch information
Xenira committed Oct 21, 2024
1 parent eb39949 commit 5c11525
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
6 changes: 6 additions & 0 deletions allowed_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -137,6 +141,7 @@ bind! {
E_RECOVERABLE_ERROR,
E_DEPRECATED,
E_USER_DEPRECATED,
EG,
HT_MIN_SIZE,
IS_ARRAY,
IS_ARRAY_EX,
Expand Down Expand Up @@ -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,
Expand Down
34 changes: 20 additions & 14 deletions src/zend/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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.
///
/// - <https://github.com/davidcole1340/ext-php-rs/issues/331>
/// - <https://github.com/php/php-src/issues/16541>
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")
Expand Down

0 comments on commit 5c11525

Please sign in to comment.