Skip to content

Commit

Permalink
Fix NULL arithmetic in System V shared memory emulation
Browse files Browse the repository at this point in the history
For the first child process execution, `TWG(shm)` is `NULL`; we need to
catch that to avoid undefined behavior.

Closes GH-17550.
  • Loading branch information
cmb69 committed Jan 25, 2025
1 parent 3a52aba commit 2e02cdf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ PHP NEWS
. Fixed bug GH-17408 (Assertion failure Zend/zend_exceptions.c).
(nielsdos, ilutov)
. Fix may_have_extra_named_args flag for ZEND_AST_UNPACK. (nielsdos)
. Fix NULL arithmetic in System V shared memory emulation for Windows. (cmb)


- DOM:
. Fixed bug GH-17500 (Segfault with requesting nodeName on nameless doctype).
Expand Down
24 changes: 13 additions & 11 deletions TSRM/tsrm_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,19 +402,21 @@ static shm_pair *shm_get(key_t key, void *addr)
shm_pair *ptr;
shm_pair *newptr;

for (ptr = TWG(shm); ptr < (TWG(shm) + TWG(shm_size)); ptr++) {
if (!ptr->descriptor) {
continue;
}
if (!addr && ptr->descriptor->shm_perm.key == key) {
break;
} else if (ptr->addr == addr) {
break;
if (TWG(shm) != NULL) {
for (ptr = TWG(shm); ptr < (TWG(shm) + TWG(shm_size)); ptr++) {
if (!ptr->descriptor) {
continue;
}
if (!addr && ptr->descriptor->shm_perm.key == key) {
break;
} else if (ptr->addr == addr) {
break;
}
}
}

if (ptr < (TWG(shm) + TWG(shm_size))) {
return ptr;
if (ptr < (TWG(shm) + TWG(shm_size))) {
return ptr;
}
}

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

0 comments on commit 2e02cdf

Please sign in to comment.