Ensure buffer for environment is large enough on OpenBSD

This commit is contained in:
Benny Baumann 2022-05-05 20:01:30 +02:00 committed by BenBE
parent 4f1269cc9f
commit db93268968

View File

@ -269,7 +269,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);
}
@ -285,6 +291,7 @@ char* Platform_getProcessEnv(pid_t pid) {
env[size + 1] = 0;
}
end:
(void) kvm_close(kt);
return env;
}