diff --git a/NEWS b/NEWS index f35a4688a09..b262a7f80d2 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,9 @@ PHP NEWS - LibXML: . Fixed bug #73533 (Invalid memory access in php_libxml_xmlCheckUTF8). (cmb) +- Pcntl: + . Fixed bug #79812 (Potential integer overflow in pcntl_exec()). (cmb) + - PDO_ODBC: . Fixed bug #80783 (PDO ODBC truncates BLOB records at every 256th byte). (cmb) diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c index 1bb67af6c54..2d19b7d4edc 100644 --- a/ext/pcntl/pcntl.c +++ b/ext/pcntl/pcntl.c @@ -955,7 +955,7 @@ PHP_FUNCTION(pcntl_exec) int envc = 0, envi = 0; char **argv = NULL, **envp = NULL; char **current_arg, **pair; - int pair_length; + size_t pair_length; zend_string *key; char *path; size_t path_len; @@ -1015,8 +1015,9 @@ PHP_FUNCTION(pcntl_exec) } /* Length of element + equal sign + length of key + null */ + ZEND_ASSERT(Z_STRLEN_P(element) < SIZE_MAX && ZSTR_LEN(key) < SIZE_MAX); + *pair = safe_emalloc(Z_STRLEN_P(element) + 1, sizeof(char), ZSTR_LEN(key) + 1); pair_length = Z_STRLEN_P(element) + ZSTR_LEN(key) + 2; - *pair = emalloc(pair_length); strlcpy(*pair, ZSTR_VAL(key), ZSTR_LEN(key) + 1); strlcat(*pair, "=", pair_length); strlcat(*pair, Z_STRVAL_P(element), pair_length);