Skip to content

Commit d74c61c

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #79812: Potential integer overflow in pcntl_exec()
2 parents 6700198 + 0a36d41 commit d74c61c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ PHP NEWS
3030
. Fixed bug #80861 (erronous array key overflow in 2D array with JIT).
3131
(Dmitry)
3232

33+
- Pcntl:
34+
. Fixed bug #79812 (Potential integer overflow in pcntl_exec()). (cmb)
35+
3336
- PDO_ODBC:
3437
. Fixed bug #80783 (PDO ODBC truncates BLOB records at every 256th byte).
3538
(cmb)

ext/pcntl/pcntl.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ PHP_FUNCTION(pcntl_exec)
785785
int envc = 0, envi = 0;
786786
char **argv = NULL, **envp = NULL;
787787
char **current_arg, **pair;
788-
int pair_length;
788+
size_t pair_length;
789789
zend_string *key;
790790
char *path;
791791
size_t path_len;
@@ -845,8 +845,9 @@ PHP_FUNCTION(pcntl_exec)
845845
}
846846

847847
/* Length of element + equal sign + length of key + null */
848+
ZEND_ASSERT(Z_STRLEN_P(element) < SIZE_MAX && ZSTR_LEN(key) < SIZE_MAX);
849+
*pair = safe_emalloc(Z_STRLEN_P(element) + 1, sizeof(char), ZSTR_LEN(key) + 1);
848850
pair_length = Z_STRLEN_P(element) + ZSTR_LEN(key) + 2;
849-
*pair = emalloc(pair_length);
850851
strlcpy(*pair, ZSTR_VAL(key), ZSTR_LEN(key) + 1);
851852
strlcat(*pair, "=", pair_length);
852853
strlcat(*pair, Z_STRVAL_P(element), pair_length);

0 commit comments

Comments
 (0)