Skip to content

Commit

Permalink
Ensure buffer for environment is large enough on NetBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
BenBE committed May 6, 2022
1 parent 0388b30 commit 4f1269c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion netbsd/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,13 @@ char* Platform_getProcessEnv(pid_t pid) {
for (char** p = ptr; *p; p++) {
size_t len = strlen(*p) + 1;

if (size + len > capacity) {
while (size + len > capacity) {
if (capacity > (SIZE_MAX / 2)) {
free(env);
env = NULL;
goto end;
}

capacity *= 2;
env = xRealloc(env, capacity);
}
Expand All @@ -327,6 +333,7 @@ char* Platform_getProcessEnv(pid_t pid) {
env[size + 1] = 0;
}

end:
(void) kvm_close(kt);
return env;
}
Expand Down

0 comments on commit 4f1269c

Please sign in to comment.