Skip to content

Commit 0a36d41

Browse files
committed
Fix #79812: Potential integer overflow in pcntl_exec()
We use the proper type, and make sure that no overflow can occur by using `safe_emalloc()` (we can assume that neither string length is `SIZE_MAX`). Closes GH-6845.
1 parent a04fac8 commit 0a36d41

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
@@ -21,6 +21,9 @@ PHP NEWS
2121
- LibXML:
2222
. Fixed bug #73533 (Invalid memory access in php_libxml_xmlCheckUTF8). (cmb)
2323

24+
- Pcntl:
25+
. Fixed bug #79812 (Potential integer overflow in pcntl_exec()). (cmb)
26+
2427
- PDO_ODBC:
2528
. Fixed bug #80783 (PDO ODBC truncates BLOB records at every 256th byte).
2629
(cmb)

ext/pcntl/pcntl.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ PHP_FUNCTION(pcntl_exec)
955955
int envc = 0, envi = 0;
956956
char **argv = NULL, **envp = NULL;
957957
char **current_arg, **pair;
958-
int pair_length;
958+
size_t pair_length;
959959
zend_string *key;
960960
char *path;
961961
size_t path_len;
@@ -1015,8 +1015,9 @@ PHP_FUNCTION(pcntl_exec)
10151015
}
10161016

10171017
/* Length of element + equal sign + length of key + null */
1018+
ZEND_ASSERT(Z_STRLEN_P(element) < SIZE_MAX && ZSTR_LEN(key) < SIZE_MAX);
1019+
*pair = safe_emalloc(Z_STRLEN_P(element) + 1, sizeof(char), ZSTR_LEN(key) + 1);
10181020
pair_length = Z_STRLEN_P(element) + ZSTR_LEN(key) + 2;
1019-
*pair = emalloc(pair_length);
10201021
strlcpy(*pair, ZSTR_VAL(key), ZSTR_LEN(key) + 1);
10211022
strlcat(*pair, "=", pair_length);
10221023
strlcat(*pair, Z_STRVAL_P(element), pair_length);

0 commit comments

Comments
 (0)