diff mbox series

[1/2] pseudo_util: Fix null pointer dereference for null envp

Message ID 20241003113018.3531433-1-richard.purdie@linuxfoundation.org
State New
Headers show
Series [1/2] pseudo_util: Fix null pointer dereference for null envp | expand

Commit Message

Richard Purdie Oct. 3, 2024, 11:30 a.m. UTC
Whilst not recommended, the kernel does accept NULL values for envp when
passed to execve and posix_spawn. Avoid pseudo_setupenvp segfaulting
when such a value is passed in and instead handle it correctly.

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 b58036f..24115ff 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -1051,7 +1051,7 @@  pseudo_setupenvp(char * const *envp) {
 	free(pseudo_get_libdir());
 	free(pseudo_get_localstatedir());
 
-	for (i = 0; envp[i]; ++i) {
+	for (i = 0; envp && envp[i]; ++i) {
 		if (STARTSWITH(envp[i], PRELINK_LIBRARIES "=")) {
 			ld_preload = envp[i];
 		}
@@ -1113,7 +1113,7 @@  pseudo_setupenvp(char * const *envp) {
 
 	free(libdir_path);
 
-	for (i = 0; envp[i]; ++i) {
+	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];