From 013d2efa519c79a300da9602e6cd599872c25ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 19 May 2021 19:58:55 +0200 Subject: [PATCH] Solaris: correct process env memory handling Allow strncpy to NUL-terminate the buffer and do not return a non free- able string literal. --- solaris/Platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/solaris/Platform.c b/solaris/Platform.c index 1d4568a0..c2ef2773 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -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;