diff mbox series

[pseudo,3/7] pseudo_util: Ensure pseudo_setupenvp handles memory consistently

Message ID 20260701131336.3578279-3-richard.purdie@linuxfoundation.org
State New
Headers show
Series [pseudo,1/7] pseudo.h: Avoid accessing unallocated memory | expand

Commit Message

Richard Purdie July 1, 2026, 1:13 p.m. UTC
Most of the new environment values added to the new environment array
returned by setupenvp are already freshly allocated memory. Ensure all
the returned values are so the data can be handled consistently and
correctly freed (for a later patch).

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 pseudo_util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/pseudo_util.c b/pseudo_util.c
index 9cafad6..126746f 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -1197,7 +1197,7 @@  pseudo_setupenvp(char * const *envp) {
 		}
 	} else {
 		/* keep old value */
-		new_envp[j++] = ld_library_path;
+		new_envp[j++] = strdup(ld_library_path);
 	}
 
 	if (ld_preload) {
@@ -1228,7 +1228,7 @@  pseudo_setupenvp(char * const *envp) {
 	for (i = 0; envp && envp[i]; ++i) {
 		if (STARTSWITH(envp[i], PRELINK_LIBRARIES "=")) continue;
 		if (STARTSWITH(envp[i], PRELINK_PATH "=")) continue;
-		new_envp[j++] = envp[i];
+		new_envp[j++] = strdup(envp[i]);
 	}
 
 	for (i = 0; pseudo_env[i].key; i++) {