Skip to content

Commit 2d2150c

Browse files
committed
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.
1 parent a6a290d commit 2d2150c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

TSRM/tsrm_win32.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,14 +374,16 @@ static process_pair *process_get(FILE *stream)
374374
process_pair *ptr;
375375
process_pair *newptr;
376376

377-
for (ptr = TWG(process); ptr < (TWG(process) + TWG(process_size)); ptr++) {
378-
if (ptr->stream == stream) {
379-
break;
377+
if (TWG(process) != NULL) {
378+
for (ptr = TWG(process); ptr < (TWG(process) + TWG(process_size)); ptr++) {
379+
if (ptr->stream == stream) {
380+
break;
381+
}
380382
}
381-
}
382383

383-
if (ptr < (TWG(process) + TWG(process_size))) {
384-
return ptr;
384+
if (ptr < (TWG(process) + TWG(process_size))) {
385+
return ptr;
386+
}
385387
}
386388

387389
newptr = (process_pair*)realloc((void*)TWG(process), (TWG(process_size)+1)*sizeof(process_pair));

0 commit comments

Comments
 (0)