Skip to content

Commit 25f924a

Browse files
committed
fixed possible null deref
1 parent 1b4103c commit 25f924a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

TSRM/tsrm_win32.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ TSRM_API int shmget(int key, int size, int flags)
625625
shm->info = info_handle;
626626
shm->descriptor = MapViewOfFileEx(shm->info, FILE_MAP_ALL_ACCESS, 0, 0, 0, NULL);
627627

628-
if (created) {
628+
if (NULL != shm->descriptor && created) {
629629
shm->descriptor->shm_perm.key = key;
630630
shm->descriptor->shm_segsz = size;
631631
shm->descriptor->shm_ctime = time(NULL);
@@ -639,8 +639,10 @@ TSRM_API int shmget(int key, int size, int flags)
639639
shm->descriptor->shm_perm.mode = shm->descriptor->shm_perm.seq = 0;
640640
}
641641

642-
if (shm->descriptor->shm_perm.key != key || size > shm->descriptor->shm_segsz ) {
643-
CloseHandle(shm->segment);
642+
if (NULL != shm->descriptor && (shm->descriptor->shm_perm.key != key || size > shm->descriptor->shm_segsz)) {
643+
if (NULL != shm->segment) {
644+
CloseHandle(shm->segment);
645+
}
644646
UnmapViewOfFile(shm->descriptor);
645647
CloseHandle(shm->info);
646648
return -1;

0 commit comments

Comments
 (0)