Mark functions not returning as sudo_noreturn

We also put NOTREACHED where it applies.
This commit is contained in:
Rose
2023-07-01 14:04:22 -04:00
parent 97e574091a
commit 45fdfa18f1
24 changed files with 47 additions and 35 deletions

View File

@@ -406,6 +406,7 @@ send_mail(const struct eventlog *evlog, const char *message)
strerror(errno)); strerror(errno));
sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys); sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys);
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
/* NOTREACHED */
case 0: case 0:
/* Grandchild continues below. */ /* Grandchild continues below. */
sudo_debug_enter(__func__, __FILE__, __LINE__, sudo_debug_subsys); sudo_debug_enter(__func__, __FILE__, __LINE__, sudo_debug_subsys);
@@ -413,6 +414,7 @@ send_mail(const struct eventlog *evlog, const char *message)
default: default:
/* Parent will wait for us. */ /* Parent will wait for us. */
_exit(EXIT_SUCCESS); _exit(EXIT_SUCCESS);
/* NOTREACHED */
} }
break; break;
default: default:
@@ -472,7 +474,7 @@ send_mail(const struct eventlog *evlog, const char *message)
"unable to fork"); "unable to fork");
sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys); sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys);
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
/* NOTREACHED */ /* NOTREACHED */
case 0: case 0:
/* Child. */ /* Child. */
exec_mailer(pfd[0]); exec_mailer(pfd[0]);

View File

@@ -35,7 +35,7 @@
sudo_dso_public int main(int argc, char *argv[]); sudo_dso_public int main(int argc, char *argv[]);
static void sudo_noreturn static void
usage(void) usage(void)
{ {
fprintf(stderr, "usage: %s [-cv] input_file ...\n", fprintf(stderr, "usage: %s [-cv] input_file ...\n",
@@ -100,6 +100,7 @@ main(int argc, char *argv[])
break; break;
default: default:
usage(); usage();
/* NOTREACHED */
} }
} }
argc -= optind; argc -= optind;

View File

@@ -34,7 +34,7 @@
sudo_dso_public int main(int argc, char *argv[]); sudo_dso_public int main(int argc, char *argv[]);
static void sudo_noreturn static void
usage(void) usage(void)
{ {
fprintf(stderr, "usage: %s [-cv] input_file ...\n", fprintf(stderr, "usage: %s [-cv] input_file ...\n",
@@ -99,6 +99,7 @@ main(int argc, char *argv[])
break; break;
default: default:
usage(); usage();
/* NOTREACHED */
} }
} }
argc -= optind; argc -= optind;

View File

@@ -34,7 +34,7 @@
sudo_dso_public int main(int argc, char *argv[]); sudo_dso_public int main(int argc, char *argv[]);
static void sudo_noreturn static void
usage(void) usage(void)
{ {
fprintf(stderr, "usage: %s [-v] inputfile\n", getprogname()); fprintf(stderr, "usage: %s [-v] inputfile\n", getprogname());
@@ -59,6 +59,7 @@ main(int argc, char *argv[])
break; break;
default: default:
usage(); usage();
/* NOTREACHED */
} }
} }
argc -= optind; argc -= optind;
@@ -110,7 +111,7 @@ main(int argc, char *argv[])
if (len == 0) if (len == 0)
printf("# word wrap disabled\n"); printf("# word wrap disabled\n");
else else
printf("# word wrap at %d characters\n", (int)len); printf("# word wrap at %zu characters\n", len);
eventlog_writeln(stdout, lines[0], strlen(lines[0]), len); eventlog_writeln(stdout, lines[0], strlen(lines[0]), len);
len++; len++;
} }

View File

@@ -121,7 +121,7 @@ done:
return ret; return ret;
} }
static void sudo_noreturn static void
usage(void) usage(void)
{ {
fprintf(stderr, "usage: %s [-cv] input_file ...\n", fprintf(stderr, "usage: %s [-cv] input_file ...\n",

View File

@@ -44,7 +44,7 @@ static struct iolog_escape_data {
sudo_dso_public int main(int argc, char *argv[]); sudo_dso_public int main(int argc, char *argv[]);
static void sudo_noreturn static void
usage(void) usage(void)
{ {
fprintf(stderr, "usage: %s datafile\n", getprogname()); fprintf(stderr, "usage: %s datafile\n", getprogname());

View File

@@ -77,5 +77,5 @@ main(int argc, char *argv[])
printf("%s: %d tests run, %d errors, %d%% success rate\n", printf("%s: %d tests run, %d errors, %d%% success rate\n",
getprogname(), ntests, errors, (ntests - errors) * 100 / ntests); getprogname(), ntests, errors, (ntests - errors) * 100 / ntests);
} }
exit(errors); return errors;
} }

View File

@@ -113,5 +113,5 @@ main(int argc, char *argv[])
printf("%s: %d tests run, %d errors, %d%% success rate\n", printf("%s: %d tests run, %d errors, %d%% success rate\n",
getprogname(), ntests, errors, (ntests - errors) * 100 / ntests); getprogname(), ntests, errors, (ntests - errors) * 100 / ntests);
} }
exit(errors); return errors;
} }

View File

@@ -38,7 +38,7 @@ sudo_dso_public int main(int argc, char *argv[]);
# define GROUP_SOURCE_ADAPTIVE GROUP_SOURCE_DYNAMIC # define GROUP_SOURCE_ADAPTIVE GROUP_SOURCE_DYNAMIC
#endif #endif
static void sudo_noreturn static void
usage(void) usage(void)
{ {
fprintf(stderr, "usage: %s [-v] conf_file\n", getprogname()); fprintf(stderr, "usage: %s [-v] conf_file\n", getprogname());
@@ -64,6 +64,7 @@ main(int argc, char *argv[])
break; break;
default: default:
usage(); usage();
/* NOTREACHED */
} }
} }
argc -= optind; argc -= optind;

View File

@@ -1973,7 +1973,7 @@ main(int argc, char *argv[])
break; break;
case 'h': case 'h':
help(); help();
break; /* NOTREACHED */
case 'n': case 'n':
nofork = true; nofork = true;
break; break;

View File

@@ -38,7 +38,7 @@
sudo_dso_public int main(int argc, char *argv[]); sudo_dso_public int main(int argc, char *argv[]);
static void sudo_noreturn static void
usage(void) usage(void)
{ {
fprintf(stderr, "usage: %s [-v] conf_file\n", getprogname()); fprintf(stderr, "usage: %s [-v] conf_file\n", getprogname());
@@ -64,6 +64,7 @@ main(int argc, char *argv[])
break; break;
default: default:
usage(); usage();
/* NOTREACHED */
} }
} }
argc -= optind; argc -= optind;

View File

@@ -1703,7 +1703,7 @@ main(int argc, char *argv[])
/* Read sudo.conf and initialize the debug subsystem. */ /* Read sudo.conf and initialize the debug subsystem. */
if (sudo_conf_read(NULL, SUDO_CONF_DEBUG) == -1) if (sudo_conf_read(NULL, SUDO_CONF_DEBUG) == -1)
exit(EXIT_FAILURE); return EXIT_FAILURE;
sudo_debug_register(getprogname(), NULL, NULL, sudo_debug_register(getprogname(), NULL, NULL,
sudo_conf_debug_files(getprogname()), -1); sudo_conf_debug_files(getprogname()), -1);
@@ -1746,7 +1746,7 @@ main(int argc, char *argv[])
break; break;
case 1: case 1:
help(); help();
break; /* NOTREACHED */
#if defined(HAVE_OPENSSL) #if defined(HAVE_OPENSSL)
case 'b': case 'b':
ca_bundle = optarg; ca_bundle = optarg;
@@ -1767,6 +1767,7 @@ main(int argc, char *argv[])
return 0; return 0;
default: default:
usage(true); usage(true);
/* NOTREACHED */
} }
} }
argc -= optind; argc -= optind;

View File

@@ -21,15 +21,16 @@
* PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com * PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
*/ */
#include <stdio.h> #include <config.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h> #include <ctype.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "sudo_plugin.h" #include "sudo_plugin.h"

View File

@@ -195,7 +195,7 @@ main(int argc, char *argv[])
break; break;
case 'h': case 'h':
help(); help();
break; /* NOTREACHED */
case 'i': case 'i':
free(conf->input_format); free(conf->input_format);
conf->input_format = strdup(optarg); conf->input_format = strdup(optarg);
@@ -258,6 +258,7 @@ main(int argc, char *argv[])
break; break;
default: default:
usage(); usage();
/* NOTREACHED */
} }
} }
argc -= optind; argc -= optind;

View File

@@ -31,7 +31,7 @@
sudo_dso_public int main(int argc, char *argv[]); sudo_dso_public int main(int argc, char *argv[]);
static void sudo_noreturn static void
usage(void) usage(void)
{ {
fprintf(stderr, "usage: %s plugin.so symbols_file\n", getprogname()); fprintf(stderr, "usage: %s plugin.so symbols_file\n", getprogname());

View File

@@ -44,7 +44,7 @@ struct sudo_plugin_event * (*plugin_event_alloc)(void);
sudo_dso_public int main(int argc, char *argv[], char *envp[]); sudo_dso_public int main(int argc, char *argv[], char *envp[]);
static void sudo_noreturn static void
usage(void) usage(void)
{ {
fprintf(stderr, "usage: %s pathname\n", getprogname()); fprintf(stderr, "usage: %s pathname\n", getprogname());

View File

@@ -65,7 +65,7 @@ check_addr(char *input)
return 0; return 0;
} }
static void sudo_noreturn static void
usage(void) usage(void)
{ {
fprintf(stderr, "usage: %s datafile\n", getprogname()); fprintf(stderr, "usage: %s datafile\n", getprogname());

View File

@@ -201,7 +201,7 @@ main(int argc, char *argv[])
break; break;
default: default:
usage(); usage();
break; /* NOTREACHED */
} }
} }
argc -= optind; argc -= optind;
@@ -731,7 +731,7 @@ testsudoers_error(const char *buf)
return fputs(buf, stderr); return fputs(buf, stderr);
} }
static void sudo_noreturn static void
usage(void) usage(void)
{ {
(void) fprintf(stderr, "usage: %s [-dt] [-G sudoers_gid] [-g group] [-h host] [-i input_format] [-P grfile] [-p pwfile] [-U sudoers_uid] [-u user] <user> <command> [args]\n", getprogname()); (void) fprintf(stderr, "usage: %s [-dt] [-G sudoers_gid] [-g group] [-h host] [-i input_format] [-P grfile] [-p pwfile] [-U sudoers_uid] [-u user] <user> <command> [args]\n", getprogname());

View File

@@ -197,7 +197,7 @@ main(int argc, char *argv[])
break; break;
case 'h': case 'h':
help(); help();
break; /* NOTREACHED */
case 'I': case 'I':
edit_includes = false; edit_includes = false;
break; break;

View File

@@ -614,6 +614,7 @@ exec_monitor(struct command_details *details, sigset_t *oset,
if (write(errpipe[1], &errno, sizeof(int)) == -1) if (write(errpipe[1], &errno, sizeof(int)) == -1)
sudo_warn(U_("unable to execute %s"), details->command); sudo_warn(U_("unable to execute %s"), details->command);
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
/* NOTREACHED */
} }
close(errpipe[1]); close(errpipe[1]);
if (intercept_fd != -1) if (intercept_fd != -1)
@@ -702,6 +703,7 @@ exec_monitor(struct command_details *details, sigset_t *oset,
#endif #endif
sudo_debug_exit_int(__func__, __FILE__, __LINE__, sudo_debug_subsys, 1); sudo_debug_exit_int(__func__, __FILE__, __LINE__, sudo_debug_subsys, 1);
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
/* NOTREACHED */
bad: bad:
debug_return_int(-1); debug_return_int(-1);

View File

@@ -633,6 +633,7 @@ exec_nopty(struct command_details *details,
} }
sudo_debug_exit_int(__func__, __FILE__, __LINE__, sudo_debug_subsys, 1); sudo_debug_exit_int(__func__, __FILE__, __LINE__, sudo_debug_subsys, 1);
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
/* NOTREACHED */
} }
sudo_debug_printf(SUDO_DEBUG_INFO, "executed %s, pid %d", details->command, sudo_debug_printf(SUDO_DEBUG_INFO, "executed %s, pid %d", details->command,
(int)ec.cmnd_pid); (int)ec.cmnd_pid);

View File

@@ -1333,6 +1333,7 @@ exec_pty(struct command_details *details,
"%s: unable to send status to parent", __func__); "%s: unable to send status to parent", __func__);
} }
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
/* NOTREACHED */
} }
/* /*

View File

@@ -148,6 +148,7 @@ main(int argc, char *argv[], char *envp[])
break; break;
default: default:
usage(); usage();
/* NOTREACHED */
} }
} }
argc -= optind; argc -= optind;

View File

@@ -1118,7 +1118,7 @@ format_plugin_settings(struct plugin_container *plugin)
goto bad; goto bad;
} }
} }
plugin_settings[i + 1] = NULL; plugin_settings[++i] = NULL;
/* Add to list of vectors to be garbage collected at exit. */ /* Add to list of vectors to be garbage collected at exit. */
if (!gc_add(GC_VECTOR, plugin_settings)) if (!gc_add(GC_VECTOR, plugin_settings))
@@ -1167,12 +1167,10 @@ policy_open(void)
sudo_debug_set_active_instance(sudo_debug_instance); sudo_debug_set_active_instance(sudo_debug_instance);
if (ok != 1) { if (ok != 1) {
if (ok == -2) if (ok == -2)
usage(); usage();
else {
/* XXX - audit */ /* XXX - audit */
sudo_fatalx("%s", U_("unable to initialize policy plugin")); sudo_fatalx("%s", U_("unable to initialize policy plugin"));
}
} }
debug_return; debug_return;
@@ -1258,7 +1256,7 @@ policy_check(int argc, char * const argv[], char *env_add[],
break; break;
case -2: case -2:
usage(); usage();
break; /* NOTREACHED */
} }
debug_return_bool(false); debug_return_bool(false);
} }
@@ -1488,7 +1486,7 @@ iolog_open(char * const command_info[], int argc, char * const argv[],
break; break;
case -2: case -2:
usage(); usage();
break; /* NOTREACHED */
default: default:
sudo_warnx(U_("error initializing I/O plugin %s"), sudo_warnx(U_("error initializing I/O plugin %s"),
plugin->name); plugin->name);
@@ -1639,7 +1637,7 @@ audit_open(void)
break; break;
case -2: case -2:
usage(); usage();
break; /* NOTREACHED */
default: default:
/* TODO: pass error message to other audit plugins */ /* TODO: pass error message to other audit plugins */
sudo_fatalx(U_("error initializing audit plugin %s"), sudo_fatalx(U_("error initializing audit plugin %s"),
@@ -1852,7 +1850,7 @@ approval_open_int(struct plugin_container *plugin)
break; break;
case -2: case -2:
usage(); usage();
break; /* NOTREACHED */
default: default:
/* XXX - audit */ /* XXX - audit */
sudo_fatalx(U_("error initializing approval plugin %s"), sudo_fatalx(U_("error initializing approval plugin %s"),
@@ -1940,7 +1938,6 @@ approval_check(char * const command_info[], char * const run_argv[],
break; break;
case -2: case -2:
usage(); usage();
break;
} }
/* Close approval plugin now that errstr has been consumed. */ /* Close approval plugin now that errstr has been consumed. */