Skip to content

Commit d1c9ff5

Browse files
committed
Fix potential NULL pointer dereference Windows shm*() functions
`shm_get()` (not to be confused with `shmget()`) returns `NULL` if reallocation fails; we need to cater to that when calling the function. Closes GH-9872.
1 parent 2b5bed9 commit d1c9ff5

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ PHP NEWS
1010
evaluation with extra named params). (Arnaud)
1111
. Fixed bug GH-9801 (Generator crashes when memory limit is exceeded during
1212
initialization). (Arnaud)
13+
. Fixed potential NULL pointer dereference in Windows shm*() functions. (cmb)
1314

1415
- Date:
1516
. Fixed bug GH-9763 (DateTimeZone ctr mishandles input and adds null byte if

TSRM/tsrm_win32.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ TSRM_API void *shmat(int key, const void *shmaddr, int flags)
702702
{/*{{{*/
703703
shm_pair *shm = shm_get(key, NULL);
704704

705-
if (!shm->segment) {
705+
if (!shm || !shm->segment) {
706706
return (void*)-1;
707707
}
708708

@@ -726,7 +726,7 @@ TSRM_API int shmdt(const void *shmaddr)
726726
shm_pair *shm = shm_get(0, (void*)shmaddr);
727727
int ret;
728728

729-
if (!shm->segment) {
729+
if (!shm || !shm->segment) {
730730
return -1;
731731
}
732732

@@ -746,7 +746,7 @@ TSRM_API int shmctl(int key, int cmd, struct shmid_ds *buf)
746746
{/*{{{*/
747747
shm_pair *shm = shm_get(key, NULL);
748748

749-
if (!shm->segment) {
749+
if (!shm || !shm->segment) {
750750
return -1;
751751
}
752752

0 commit comments

Comments
 (0)