diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-02-26 15:32:18 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-06-05 14:25:07 +0200 |
commit | a31f46421d7bf6f55dd9ac5876b8e2eacf7e0708 (patch) | |
tree | 24ffd7c5ae5e321c3994048fdd0fd9f68ae7457c /ext/pcntl/pcntl.c | |
parent | 528aa7932a839fc6319979c34aa372805d8dc41c (diff) | |
download | php-git-a31f46421d7bf6f55dd9ac5876b8e2eacf7e0708.tar.gz |
Allow exceptions in __toString()
RFC: https://wiki.php.net/rfc/tostring_exceptions
And convert some object to string conversion related recoverable
fatal errors into Error exceptions.
Improve exception safety of internal code performing string
conversions.
Diffstat (limited to 'ext/pcntl/pcntl.c')
-rw-r--r-- | ext/pcntl/pcntl.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c index 63751d4b17..300de1e7d4 100644 --- a/ext/pcntl/pcntl.c +++ b/ext/pcntl/pcntl.c @@ -967,6 +967,7 @@ PHP_FUNCTION(pcntl_exec) if (ZEND_NUM_ARGS() > 1) { /* Build argument list */ + SEPARATE_ARRAY(args); args_hash = Z_ARRVAL_P(args); argc = zend_hash_num_elements(args_hash); @@ -975,20 +976,25 @@ PHP_FUNCTION(pcntl_exec) current_arg = argv+1; ZEND_HASH_FOREACH_VAL(args_hash, element) { if (argi >= argc) break; - convert_to_string_ex(element); + if (!try_convert_to_string(element)) { + efree(argv); + return; + } + *current_arg = Z_STRVAL_P(element); argi++; current_arg++; } ZEND_HASH_FOREACH_END(); - *(current_arg) = NULL; + *current_arg = NULL; } else { argv = emalloc(2 * sizeof(char *)); - *argv = path; - *(argv+1) = NULL; + argv[0] = path; + argv[1] = NULL; } if ( ZEND_NUM_ARGS() == 3 ) { /* Build environment pair list */ + SEPARATE_ARRAY(envs); envs_hash = Z_ARRVAL_P(envs); envc = zend_hash_num_elements(envs_hash); @@ -1001,7 +1007,12 @@ PHP_FUNCTION(pcntl_exec) zend_string_addref(key); } - convert_to_string_ex(element); + if (!try_convert_to_string(element)) { + zend_string_release(key); + efree(argv); + efree(envp); + return; + } /* Length of element + equal sign + length of key + null */ pair_length = Z_STRLEN_P(element) + ZSTR_LEN(key) + 2; |