Fix NULL arithmetic during system program execution

For the first child process execution, `TWG(process)` is `NULL`; we
need to catch that to avoid undefined behavior.

Closes GH-17470.
This commit is contained in:
Christoph M. Becker 2025-01-14 23:34:27 +01:00
parent e4473abefc
commit 022a5fca91
No known key found for this signature in database
GPG key ID: D66C9593118BCCB6
2 changed files with 10 additions and 6 deletions

2
NEWS
View file

@ -9,6 +9,8 @@ PHP NEWS
(nielsdos)
. Fixed bug GH-17214 (Relax final+private warning for trait methods with
inherited final). (ilutov)
. Fixed NULL arithmetic during system program execution on Windows. (cmb,
nielsdos)
- Enchant:
. Fix crashes in enchant when passing null bytes. (nielsdos)

View file

@ -374,14 +374,16 @@ static process_pair *process_get(FILE *stream)
process_pair *ptr;
process_pair *newptr;
for (ptr = TWG(process); ptr < (TWG(process) + TWG(process_size)); ptr++) {
if (ptr->stream == stream) {
break;
if (TWG(process) != NULL) {
for (ptr = TWG(process); ptr < (TWG(process) + TWG(process_size)); ptr++) {
if (ptr->stream == stream) {
break;
}
}
}
if (ptr < (TWG(process) + TWG(process_size))) {
return ptr;
if (ptr < (TWG(process) + TWG(process_size))) {
return ptr;
}
}
newptr = (process_pair*)realloc((void*)TWG(process), (TWG(process_size)+1)*sizeof(process_pair));