From: Todd C. Miller Date: Tue, 7 Aug 2012 16:04:37 +0000 (-0400) Subject: Fix some warnings from clang checker-267 X-Git-Tag: SUDO_1_7_10~25 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f5d58628716c4cf5851eea739d93cd40bb4b2ac9;p=sudo Fix some warnings from clang checker-267 --HG-- branch : 1.7 --- diff --git a/env.c b/env.c index b1e0971f6..7afd04620 100644 --- a/env.c +++ b/env.c @@ -42,6 +42,9 @@ #ifdef HAVE_UNISTD_H # include #endif /* HAVE_UNISTD_H */ +#ifdef HAVE_INTTYPES_H +# include +#endif #ifdef HAVE_LOGIN_CAP_H # include # ifndef LOGIN_SETENV @@ -50,10 +53,25 @@ #endif /* HAVE_LOGIN_CAP_H */ #include #include +#include #include #include "sudo.h" +/* + * If there is no SIZE_MAX or SIZE_T_MAX we have to assume that size_t + * could be signed (as it is on SunOS 4.x). This just means that + * emalloc2() and erealloc3() cannot allocate huge amounts on such a + * platform but that is OK since sudo doesn't need to do so anyway. + */ +#ifndef SIZE_MAX +# ifdef SIZE_T_MAX +# define SIZE_MAX SIZE_T_MAX +# else +# define SIZE_MAX INT_MAX +# endif /* SIZE_T_MAX */ +#endif /* SIZE_MAX */ + /* * Flags used in rebuild_env() */ @@ -244,7 +262,7 @@ env_init(lazy) memset(env.envp, 0, env.env_size * sizeof(char *)); #endif memcpy(env.envp, environ, len * sizeof(char *)); - env.envp[len] = '\0'; + env.envp[len] = NULL; env.owned = TRUE; } } @@ -445,7 +463,9 @@ sudo_putenv(str, dupcheck, overwrite) int found = FALSE; /* Make sure there is room for the new entry plus a NULL. */ - if (env.env_len + 2 > env.env_size) { + if (env.env_size > 2 && env.env_len > env.env_size - 2) { + if (env.env_size > SIZE_MAX - 128) + errorx(1, "internal error, sudo_putenv() overflow"); env.env_size += 128; if (env.owned) { env.envp = erealloc3(env.envp, env.env_size, sizeof(char *)); @@ -469,11 +489,12 @@ sudo_putenv(str, dupcheck, overwrite) if (dupcheck) { len = (strchr(str, '=') - str) + 1; - for (ep = env.envp; !found && *ep != NULL; ep++) { + for (ep = env.envp; *ep != NULL; ep++) { if (strncmp(str, *ep, len) == 0) { if (overwrite) *ep = str; found = TRUE; + break; } } /* Prune out duplicate variables. */ diff --git a/getline.c b/getline.c index 2b3d32464..8deab41c2 100644 --- a/getline.c +++ b/getline.c @@ -56,7 +56,7 @@ getline(bufp, bufsizep, fp) buf = fgetln(fp, &len); if (buf) { bufsize = *bufp ? *bufsizep : 0; - if (bufsize < len + 1) { + if (bufsize == 0 || bufsize < len + 1) { bufsize = len + 1; *bufp = erealloc(*bufp, bufsize); *bufsizep = bufsize; diff --git a/visudo.c b/visudo.c index e19b9864a..1ca6a55b0 100644 --- a/visudo.c +++ b/visudo.c @@ -451,6 +451,9 @@ reparse_sudoers(editor, args, strict, quiet) FILE *fp; int ch; + if (tq_empty(&sudoerslist)) + return TRUE; + /* * Parse the edited sudoers files and do sanity checking */