Skip to content

Commit

Permalink
Fix NULL arithmetic during system program execution
Browse files Browse the repository at this point in the history
For the first child process execution, `TWG(process)` is `NULL`; we
need to catch that to avoid undefined behavior.
  • Loading branch information
cmb69 committed Jan 14, 2025
1 parent a6a290d commit 2d2150c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions TSRM/tsrm_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,16 @@ static process_pair *process_get(FILE *stream)
process_pair *ptr;
process_pair *newptr;

for (ptr = TWG(process); ptr < (TWG(process) + TWG(process_size)); ptr++) {
if (ptr->stream == stream) {
break;
if (TWG(process) != NULL) {
for (ptr = TWG(process); ptr < (TWG(process) + TWG(process_size)); ptr++) {
if (ptr->stream == stream) {
break;
}
}
}

if (ptr < (TWG(process) + TWG(process_size))) {
return ptr;
if (ptr < (TWG(process) + TWG(process_size))) {
return ptr;
}
}

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

0 comments on commit 2d2150c

Please sign in to comment.