-
Notifications
You must be signed in to change notification settings - Fork 8k
Aggressively use actual function parameters in php_verror
#12276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
2293ae4
4324e64
060d971
83a6868
3f0e8cf
6e88792
8e0e56b
9e866be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| --TEST-- | ||
| Displaying function arguments in errors | ||
| --INI-- | ||
| error_include_args=On | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| // A function that sets its own parameters in docref call, to compare | ||
| unlink('/'); | ||
|
|
||
| // Something with sensitive parameters that exists in a minimal build, | ||
| // and also doesn't set anything in the docref call. cost is set to 4 | ||
| // to keep the test fast | ||
| $flags = ["salt" => "123456789012345678901" . chr(0), "cost" => 4]; | ||
| password_hash("test", PASSWORD_BCRYPT, $flags); | ||
|
|
||
| ini_set("error_include_args", "Off"); | ||
|
|
||
| unlink('/'); | ||
| password_hash("test", PASSWORD_BCRYPT, $flags); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Warning: unlink('/'): %s in %s on line %d | ||
|
|
||
| Warning: password_hash(Object(SensitiveParameterValue), '2y', Array): The "salt" option has been ignored, since providing a custom salt is no longer supported in %s on line %d | ||
|
|
||
| Warning: unlink(/): %s in %s on line %d | ||
|
|
||
| Warning: password_hash(): The "salt" option has been ignored, since providing a custom salt is no longer supported in %s on line %d |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -542,6 +542,31 @@ static void _build_trace_args(zval *arg, smart_str *str) /* {{{ */ | |||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| /* }}} */ | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| static void _build_trace_args_list(zval *tmp, smart_str *str) /* {{{ */ | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| if (EXPECTED(Z_TYPE_P(tmp) == IS_ARRAY)) { | ||||||||||||||||||||||||||||
| size_t last_len = ZSTR_LEN(str->s); | ||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know you just moved the code, but this should be smart_str_get_len() (which safely handles the case where no allocation has been made yet (which might be the reason you got the ASAN issues?). A simpler solution might also be to append the |
||||||||||||||||||||||||||||
| zend_string *name; | ||||||||||||||||||||||||||||
| zval *arg; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(tmp), name, arg) { | ||||||||||||||||||||||||||||
| if (name) { | ||||||||||||||||||||||||||||
| smart_str_append(str, name); | ||||||||||||||||||||||||||||
| smart_str_appends(str, ": "); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| _build_trace_args(arg, str); | ||||||||||||||||||||||||||||
| } ZEND_HASH_FOREACH_END(); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (last_len != ZSTR_LEN(str->s)) { | ||||||||||||||||||||||||||||
| ZSTR_LEN(str->s) -= 2; /* remove last ', ' */ | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||
| /* only happens w/ reflection abuse (Zend/tests/bug63762.phpt) */ | ||||||||||||||||||||||||||||
| zend_error(E_WARNING, "args element is not an array"); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| /* }}} */ | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| static void _build_trace_string(smart_str *str, const HashTable *ht, uint32_t num) /* {{{ */ | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| zval *file, *tmp; | ||||||||||||||||||||||||||||
|
|
@@ -588,30 +613,45 @@ static void _build_trace_string(smart_str *str, const HashTable *ht, uint32_t nu | |||||||||||||||||||||||||||
| smart_str_appendc(str, '('); | ||||||||||||||||||||||||||||
| tmp = zend_hash_find_known_hash(ht, ZSTR_KNOWN(ZEND_STR_ARGS)); | ||||||||||||||||||||||||||||
| if (tmp) { | ||||||||||||||||||||||||||||
| if (EXPECTED(Z_TYPE_P(tmp) == IS_ARRAY)) { | ||||||||||||||||||||||||||||
| size_t last_len = ZSTR_LEN(str->s); | ||||||||||||||||||||||||||||
| zend_string *name; | ||||||||||||||||||||||||||||
| zval *arg; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(tmp), name, arg) { | ||||||||||||||||||||||||||||
| if (name) { | ||||||||||||||||||||||||||||
| smart_str_append(str, name); | ||||||||||||||||||||||||||||
| smart_str_appends(str, ": "); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| _build_trace_args(arg, str); | ||||||||||||||||||||||||||||
| } ZEND_HASH_FOREACH_END(); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (last_len != ZSTR_LEN(str->s)) { | ||||||||||||||||||||||||||||
| ZSTR_LEN(str->s) -= 2; /* remove last ', ' */ | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||
| zend_error(E_WARNING, "args element is not an array"); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| _build_trace_args_list(tmp, str); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| smart_str_appends(str, ")\n"); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| /* }}} */ | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /* {{{ Gets the function arguments printed as a string from a backtrace frame. */ | ||||||||||||||||||||||||||||
| ZEND_API zend_string *zend_trace_function_args_to_string(const HashTable *frame) { | ||||||||||||||||||||||||||||
| smart_str str = {0}; | ||||||||||||||||||||||||||||
| smart_str_appends(&str, ""); | ||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does nothing (useful):
Suggested change
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| zval *tmp = zend_hash_find_known_hash(frame, ZSTR_KNOWN(ZEND_STR_ARGS)); | ||||||||||||||||||||||||||||
| if (tmp) { | ||||||||||||||||||||||||||||
| _build_trace_args_list(tmp, &str); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return smart_str_extract(&str); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| /* }}} */ | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /* {{{ Gets the currently executing function's arguments as a string. Used by php_verror. */ | ||||||||||||||||||||||||||||
| ZEND_API zend_string *zend_trace_current_function_args_string(void) { | ||||||||||||||||||||||||||||
| zend_string *dynamic_params = NULL; | ||||||||||||||||||||||||||||
| /* get a backtrace to snarf function args */ | ||||||||||||||||||||||||||||
| zval backtrace; | ||||||||||||||||||||||||||||
| zend_fetch_debug_backtrace(&backtrace, /* skip_last */ 0, /* options */ 0, /* limit */ 1); | ||||||||||||||||||||||||||||
| /* can fail esp if low memory condition */ | ||||||||||||||||||||||||||||
| if (Z_TYPE(backtrace) != IS_ARRAY) { | ||||||||||||||||||||||||||||
| return NULL; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| zval *first_frame = zend_hash_index_find(Z_ARRVAL(backtrace), 0); | ||||||||||||||||||||||||||||
| if (first_frame) { | ||||||||||||||||||||||||||||
| dynamic_params = zend_trace_function_args_to_string(Z_ARRVAL_P(first_frame)); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+643
to
+649
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the
Suggested change
Since |
||||||||||||||||||||||||||||
| zval_ptr_dtor(&backtrace); | ||||||||||||||||||||||||||||
| return dynamic_params; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| /* }}} */ | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| ZEND_API zend_string *zend_trace_to_string(const HashTable *trace, bool include_main) { | ||||||||||||||||||||||||||||
| zend_ulong index; | ||||||||||||||||||||||||||||
| zval *frame; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identifiers starting with an underscore are reserved. The
staticis sufficient to make the function private.