Add asserts() to avoid static analyzer false positives.

This commit is contained in:
Todd C. Miller
2019-08-30 11:13:35 -06:00
parent 679cd38238
commit ffaef7939a
2 changed files with 17 additions and 0 deletions

View File

@@ -41,6 +41,7 @@
#include <ctype.h> #include <ctype.h>
#include <grp.h> #include <grp.h>
#include <pwd.h> #include <pwd.h>
#include <assert.h>
#include <sudo_usage.h> #include <sudo_usage.h>
#include "sudo.h" #include "sudo.h"
@@ -310,6 +311,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv,
break; break;
#ifdef HAVE_BSD_AUTH_H #ifdef HAVE_BSD_AUTH_H
case 'a': case 'a':
assert(optarg != NULL);
if (*optarg == '\0') if (*optarg == '\0')
usage(1); usage(1);
sudo_settings[ARG_BSDAUTH_TYPE].value = optarg; sudo_settings[ARG_BSDAUTH_TYPE].value = optarg;
@@ -322,6 +324,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv,
SET(tgetpass_flags, TGP_BELL); SET(tgetpass_flags, TGP_BELL);
break; break;
case 'C': case 'C':
assert(optarg != NULL);
if (strtonum(optarg, 3, INT_MAX, NULL) == 0) { if (strtonum(optarg, 3, INT_MAX, NULL) == 0) {
sudo_warnx(U_("the argument to -C must be a number greater than or equal to 3")); sudo_warnx(U_("the argument to -C must be a number greater than or equal to 3"));
usage(1); usage(1);
@@ -330,6 +333,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv,
break; break;
#ifdef HAVE_LOGIN_CAP_H #ifdef HAVE_LOGIN_CAP_H
case 'c': case 'c':
assert(optarg != NULL);
if (*optarg == '\0') if (*optarg == '\0')
usage(1); usage(1);
sudo_settings[ARG_LOGIN_CLASS].value = optarg; sudo_settings[ARG_LOGIN_CLASS].value = optarg;
@@ -359,6 +363,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv,
valid_flags = MODE_NONINTERACTIVE; valid_flags = MODE_NONINTERACTIVE;
break; break;
case 'g': case 'g':
assert(optarg != NULL);
if (*optarg == '\0') if (*optarg == '\0')
usage(1); usage(1);
runas_group = optarg; runas_group = optarg;
@@ -389,6 +394,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv,
} }
/* FALLTHROUGH */ /* FALLTHROUGH */
case OPT_HOSTNAME: case OPT_HOSTNAME:
assert(optarg != NULL);
if (*optarg == '\0') if (*optarg == '\0')
usage(1); usage(1);
sudo_settings[ARG_REMOTE_HOST].value = optarg; sudo_settings[ARG_REMOTE_HOST].value = optarg;
@@ -426,15 +432,18 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv,
break; break;
case 'p': case 'p':
/* An empty prompt is allowed. */ /* An empty prompt is allowed. */
assert(optarg != NULL);
sudo_settings[ARG_PROMPT].value = optarg; sudo_settings[ARG_PROMPT].value = optarg;
break; break;
#ifdef HAVE_SELINUX #ifdef HAVE_SELINUX
case 'r': case 'r':
assert(optarg != NULL);
if (*optarg == '\0') if (*optarg == '\0')
usage(1); usage(1);
sudo_settings[ARG_SELINUX_ROLE].value = optarg; sudo_settings[ARG_SELINUX_ROLE].value = optarg;
break; break;
case 't': case 't':
assert(optarg != NULL);
if (*optarg == '\0') if (*optarg == '\0')
usage(1); usage(1);
sudo_settings[ARG_SELINUX_TYPE].value = optarg; sudo_settings[ARG_SELINUX_TYPE].value = optarg;
@@ -442,6 +451,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv,
#endif #endif
case 'T': case 'T':
/* Plugin determines whether empty timeout is allowed. */ /* Plugin determines whether empty timeout is allowed. */
assert(optarg != NULL);
sudo_settings[ARG_TIMEOUT].value = optarg; sudo_settings[ARG_TIMEOUT].value = optarg;
break; break;
case 'S': case 'S':
@@ -452,11 +462,13 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv,
SET(flags, MODE_SHELL); SET(flags, MODE_SHELL);
break; break;
case 'U': case 'U':
assert(optarg != NULL);
if (*optarg == '\0') if (*optarg == '\0')
usage(1); usage(1);
list_user = optarg; list_user = optarg;
break; break;
case 'u': case 'u':
assert(optarg != NULL);
if (*optarg == '\0') if (*optarg == '\0')
usage(1); usage(1);
runas_user = optarg; runas_user = optarg;

View File

@@ -45,6 +45,11 @@
# include <priv.h> # include <priv.h>
#endif #endif
/* Enable asserts() to avoid static analyzer false positives. */
#if !defined(SUDO_DEVEL) && !defined(__clang_analyzer__)
# define NDEBUG
#endif
#ifdef __TANDEM #ifdef __TANDEM
# define ROOT_UID 65535 # define ROOT_UID 65535
#else #else