From 3421c8b6cedc582ed5eab573f59d4feddc7e1ab3 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 26 Jul 2022 11:44:12 -0600 Subject: [PATCH] Fix potential NULL pointer deference found by clang-analyzer. --- lib/util/sudo_debug.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/util/sudo_debug.c b/lib/util/sudo_debug.c index a2ead5228..c06ba8cde 100644 --- a/lib/util/sudo_debug.c +++ b/lib/util/sudo_debug.c @@ -861,7 +861,7 @@ sudo_debug_execve2_v1(int level, const char *path, char *const argv[], char *con continue; /* Log envp for debug level "debug". */ - if (output->settings[subsys] >= SUDO_DEBUG_DEBUG - 1 && envp[0] != NULL) + if (output->settings[subsys] >= SUDO_DEBUG_DEBUG - 1 && envp != NULL) log_envp = true; /* Alloc and build up buffer. */ @@ -873,7 +873,7 @@ sudo_debug_execve2_v1(int level, const char *path, char *const argv[], char *con buflen += strlen(*av) + 1; buflen--; } - if (envp != NULL && log_envp) { + if (log_envp && envp[0] != NULL) { buflen += sizeof(" []") - 1; for (av = envp; *av; av++) buflen += strlen(*av) + 1; @@ -904,7 +904,7 @@ sudo_debug_execve2_v1(int level, const char *path, char *const argv[], char *con cp[-1] = ']'; } - if (envp != NULL && log_envp) { + if (log_envp && envp[0] != NULL) { *cp++ = ' '; *cp++ = '['; for (av = envp; *av; av++) {