diff mbox series

[pseudo,1/3] pseudo_setupenvp: Allocate space for new env vars if needed

Message ID 20260320-some-fixes-v1-1-f5ca33dbf180@pbarker.dev
State New
Headers show
Series Memory management fixes and b4 config | expand

Commit Message

Paul Barker March 20, 2026, 12:01 p.m. UTC
If LD_LIBRARY_PATH or LD_PRELOAD were not included in the existing
environment, we need to make space for them. Otherwise we have the
potential for a buffer overflow. It's pretty unlikely as it can only be
triggered when an application running under pseudo calls execve(),
posix_spawn() or posix_spawnp() with a cleaned environment that doesn't
include the above variables, but it's better to be safe than sorry.

Issue found by Claude Opus 4.6, but fix implemented by me.

Signed-off-by: Paul Barker <paul@pbarker.dev>
---
 pseudo_util.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff mbox series

Patch

diff --git a/pseudo_util.c b/pseudo_util.c
index 671ab7fd9b81..4abcc155c286 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -1141,6 +1141,14 @@  pseudo_setupenvp(char * const *envp) {
 		++env_count;
 	}
 
+	/* If LD_PRELOAD or LD_LIBRARY_PATH were not included in the existing
+	 * environment, we need to make space for them.
+	 */
+	if (!ld_preload)
+		env_count++;
+	if (!ld_library_path)
+		env_count++;
+
 	for (i = 0; pseudo_env[i].key; i++) {
 		size_pseudoenv++;
 	}