Skip to content

Commit 2e02cdf

Browse files
committed
Fix NULL arithmetic in System V shared memory emulation
For the first child process execution, `TWG(shm)` is `NULL`; we need to catch that to avoid undefined behavior. Closes GH-17550.
1 parent 3a52aba commit 2e02cdf

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ PHP NEWS
1515
. Fixed bug GH-17408 (Assertion failure Zend/zend_exceptions.c).
1616
(nielsdos, ilutov)
1717
. Fix may_have_extra_named_args flag for ZEND_AST_UNPACK. (nielsdos)
18+
. Fix NULL arithmetic in System V shared memory emulation for Windows. (cmb)
19+
1820

1921
- DOM:
2022
. Fixed bug GH-17500 (Segfault with requesting nodeName on nameless doctype).

TSRM/tsrm_win32.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -402,19 +402,21 @@ static shm_pair *shm_get(key_t key, void *addr)
402402
shm_pair *ptr;
403403
shm_pair *newptr;
404404

405-
for (ptr = TWG(shm); ptr < (TWG(shm) + TWG(shm_size)); ptr++) {
406-
if (!ptr->descriptor) {
407-
continue;
408-
}
409-
if (!addr && ptr->descriptor->shm_perm.key == key) {
410-
break;
411-
} else if (ptr->addr == addr) {
412-
break;
405+
if (TWG(shm) != NULL) {
406+
for (ptr = TWG(shm); ptr < (TWG(shm) + TWG(shm_size)); ptr++) {
407+
if (!ptr->descriptor) {
408+
continue;
409+
}
410+
if (!addr && ptr->descriptor->shm_perm.key == key) {
411+
break;
412+
} else if (ptr->addr == addr) {
413+
break;
414+
}
413415
}
414-
}
415416

416-
if (ptr < (TWG(shm) + TWG(shm_size))) {
417-
return ptr;
417+
if (ptr < (TWG(shm) + TWG(shm_size))) {
418+
return ptr;
419+
}
418420
}
419421

420422
newptr = (shm_pair*)realloc((void*)TWG(shm), (TWG(shm_size)+1)*sizeof(shm_pair));

0 commit comments

Comments
 (0)