Solaris: correct process env memory handling

Allow strncpy to NUL-terminate the buffer and do not return a non free-
able string literal.
This commit is contained in:
Christian Göttsche 2021-05-19 19:58:55 +02:00 committed by cgzones
parent 27be880d0f
commit 013d2efa51
1 changed files with 2 additions and 2 deletions

View File

@ -259,7 +259,7 @@ static int Platform_buildenv(void* accum, struct ps_prochandle* Phandle, uintptr
return 1;
}
strlcpy( accump->env + accump->size, str, (accump->capacity - accump->size));
strncpy( accump->env + accump->size + thissz + 1, "\n", 1);
strncpy( accump->env + accump->size + thissz + 1, "\n", 2);
accump->size = accump->size + thissz + 1;
return 0;
}
@ -271,7 +271,7 @@ char* Platform_getProcessEnv(pid_t pid) {
struct ps_prochandle* Phandle;
if ((Phandle = Pgrab(realpid, PGRAB_RDONLY, &graberr)) == NULL) {
return "Unable to read process environment.";
return NULL;
}
envBuilder.capacity = 4096;