restorecond: add noreturn attribute to exitApp()
PATCH 1/6 restorecond: add noreturn attribute to exitApp()
This makes it possible for static analyzers such as clang's one to understand that strings_list_add() cannot dereference a NULL pointer in the following code:
if (!newptr)
exitApp("Out of Memory");
newptr->string = strdup(string);--- restorecond/restorecond.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
restorecond/restorecond.h +1 -1
@@ -33,7 +33,7 @@ extern int run_as_user;extern int start (void );extern int server (int ,const char *watch_file); -extern void exitApp (const char *msg); +extern void exitApp (const char *msg) __attribute__((__noreturn__));extern void read_config (int fd,const char *watch_file);extern int watch (int fd,const char *watch_file);
Signature · 1 line
2.11.1
PATCH 2/6 checkpolicy: add noreturn attribute to usage()
While at it, make usage() static and mark its argument as const.
--- checkpolicy/checkmodule.c | 2 +- checkpolicy/checkpolicy.c | 2 +- checkpolicy/test/dismod.c | 2 +- checkpolicy/test/dispol.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
checkpolicy/checkmodule.c +1 -1
@@ -124,7 +124,7 @@ static int write_binary_policy(policydb_t * p, FILE *outfp)return policydb_write (p, &pf); } -static void usage (char *progname) +static __attribute__((__noreturn__))void usage (const char *progname) {printf ("usage: %s [-h] [-V] [-b] [-C] [-U handle_unknown] [-m] [-M] [-o FILE] [INPUT]\n" , progname);printf ("Build base and policy modules.\n" );
checkpolicy/checkpolicy.c +1 -1
@@ -102,7 +102,7 @@ static const char *binfile = "policy";unsigned int policyvers =POLICYDB_VERSION_MAX ; -void usage (char *progname) +static __attribute__((__noreturn__))void usage (const char *progname) {printf ("usage: %s [-b] [-C] [-d] [-U handle_unknown (allow,deny,reject)] [-M]"
checkpolicy/test/dismod.c +1 -1
@@ -65,7 +65,7 @@ static const char *symbol_labels[9] = { "levels ", "cats ", "attribs" }; -void usage (const char *progname) +static __attribute__((__noreturn__))void usage (const char *progname) {printf ("usage: %s binary_pol_file\n\n" , progname);exit (1 );
checkpolicy/test/dispol.c +1 -1
@@ -36,7 +36,7 @@static policydb_t policydb; -void usage (const char *progname) +static __attribute__((__noreturn__))void usage (const char *progname) {printf ("usage: %s binary_pol_file\n\n" , progname);exit (1 );
Signature · 1 line
2.11.1
PATCH 3/6 secilc: add noreturn attribute to usage()
In reply to Nicolas IoossWhile at it, make usage() static and mark its argument as const.
--- secilc/secil2conf.c | 2 +- secilc/secilc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
secilc/secil2conf.c +1 -1
@@ -41,7 +41,7 @@#endif #include <sepol/policydb.h> -void usage (char *prog) +static __attribute__((__noreturn__))void usage (const char *prog) {printf ("Usage: %s [OPTION]... FILE...\n" , prog);printf ("\n" );
secilc/secilc.c +1 -1
@@ -41,7 +41,7 @@#endif #include <sepol/policydb.h> -void usage (char *prog) +static __attribute__((__noreturn__))void usage (const char *prog) {printf ("Usage: %s [OPTION]... FILE...\n" , prog);printf ("\n" );
Signature · 1 line
2.11.1
PATCH 4/6 mcstrans: add noreturn attribute to usage()
In reply to Nicolas Iooss--- mcstrans/utils/transcon.c | 2 +- mcstrans/utils/untranscon.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
mcstrans/utils/transcon.c +1 -1
@@ -7,7 +7,7 @@#include <selinux/selinux.h> #include "mcstrans.h" -void usage (const char *progname) +static __attribute__((__noreturn__))void usage (const char *progname) {fprintf (stderr,"usage: %s context\n" , progname);exit (1 );
mcstrans/utils/untranscon.c +1 -1
@@ -7,7 +7,7 @@#include <selinux/selinux.h> #include "mcstrans.h" -void usage (const char *progname) +static __attribute__((__noreturn__))void usage (const char *progname) {fprintf (stderr,"usage: %s context\n" , progname);exit (1 );
Signature · 1 line
2.11.1
PATCH 5/6 semodule-utils: add noreturn attribute to usage()
In reply to Nicolas Iooss--- semodule-utils/semodule_deps/semodule_deps.c | 2 +- semodule-utils/semodule_expand/semodule_expand.c | 2 +- semodule-utils/semodule_link/semodule_link.c | 2 +- semodule-utils/semodule_package/semodule_package.c | 2 +- semodule-utils/semodule_package/semodule_unpackage.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-)
semodule-utils/semodule_deps/semodule_deps.c +1 -1
@@ -42,7 +42,7 @@ extern int optind;*/ #define BASE_NAME ((char *)"BASE") -static void usage (char *program_name) +static __attribute__((__noreturn__))void usage (const char *program_name) {printf ("usage: %s [-v -g -b] basemodpkg modpkg1 [modpkg2 ... ]\n" , program_name);
semodule-utils/semodule_expand/semodule_expand.c +1 -1
@@ -28,7 +28,7 @@ int policyvers = 0;#define EXPANDPOLICY_VERSION "1.0" -static void usage (char *program_name) +static __attribute__((__noreturn__))void usage (const char *program_name) {printf ("usage: %s [-V -a -c [version]] basemodpkg outputfile\n" , program_name);
semodule-utils/semodule_link/semodule_link.c +1 -1
@@ -25,7 +25,7 @@ char *progname;extern char *optarg;extern int optind; -static void usage (char *program_name) +static __attribute__((__noreturn__))void usage (const char *program_name) {printf ("usage: %s [-Vv] [-o outfile] basemodpkg modpkg1 [modpkg2]...\n" , program_name);
semodule-utils/semodule_package/semodule_package.c +1 -1
@@ -22,7 +22,7 @@char *progname =NULL ;extern char *optarg; -static void usage (const char *prog) +static __attribute__((__noreturn__))void usage (const char *prog) {printf ("usage: %s -o <output file> -m <module> [-f <file contexts>]\n" , prog);
semodule-utils/semodule_package/semodule_unpackage.c +1 -1
@@ -14,7 +14,7 @@char *progname =NULL ;extern char *optarg; -static void usage (void ) +static __attribute__((__noreturn__))void usage (void ) {printf ("usage: %s ppfile modfile [fcfile]\n" , progname);exit (1 );
Signature · 1 line
2.11.1
PATCH 6/6 policycoreutils: add noreturn attribute to usage()
In reply to Nicolas Iooss--- policycoreutils/hll/pp/pp.c | 2 +- policycoreutils/load_policy/load_policy.c | 2 +- policycoreutils/secon/secon.c | 2 +- policycoreutils/setfiles/restorecon_xattr.c | 2 +- policycoreutils/setfiles/setfiles.c | 2 +- policycoreutils/setsebool/setsebool.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-)
policycoreutils/hll/pp/pp.c +1 -1
@@ -46,7 +46,7 @@ static void log_err(const char *fmt, ...) } } -static void usage (int err) +static __attribute__((__noreturn__))void usage (int err) {fprintf (stderr,"Usage: %s [OPTIONS] [IN_FILE [OUT_FILE]]\n" , progname);fprintf (stderr,"\n" );
policycoreutils/load_policy/load_policy.c +1 -1
@@ -17,7 +17,7 @@#define PACKAGE "policycoreutils"/* the name of this package lang translation */ #endif -void usage (char *progname) +static __attribute__((__noreturn__))void usage (const char *progname) {fprintf (stderr,_ ("usage: %s [-qi]\n" ), progname);exit (1 );
policycoreutils/secon/secon.c +1 -1
@@ -73,7 +73,7 @@ struct { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, OPTS_FROM_ARG, {0} } }; -static void usage (const char *name,int exit_code) +static __attribute__((__noreturn__))void usage (const char *name,int exit_code) {fprintf (exit_code ? stderr : stdout, " Usage: %s [-%s] [ context | - ]\n"
policycoreutils/setfiles/restorecon_xattr.c +1 -1
@@ -14,7 +14,7 @@#include "restore.h" -static void usage (const char *progname) +static __attribute__((__noreturn__))void usage (const char *progname) {fprintf (stderr, "\nusage: %s [-vnrmdD] [-e directory] [-f specfile] pathname\n"
policycoreutils/setfiles/setfiles.c +1 -1
@@ -39,7 +39,7 @@ static int iamrestorecon;static int ctx_validate;/* Validate contexts */ static const char *altpath;/* Alternate path to file_contexts */ -void usage (const char *const name) +static __attribute__((__noreturn__))void usage (const char *const name) {if (iamrestorecon) { fprintf(stderr,
policycoreutils/setsebool/setsebool.c +1 -1
@@ -23,7 +23,7 @@ int verbose = 0;int setbool (char **list,size_t start,size_t end); -void usage (void ) +static __attribute__((__noreturn__))void usage (void ) { fputs ("\nUsage: setsebool [ -NPV ] boolean value | bool1=val1 bool2=val2...\n\n",
Signature · 1 line
2.11.1
Quoted 9 lines · Nicolas Iooss
This makes it possible for static analyzers such as clang's one to understand that
strings_list_add()cannot dereference a NULL pointer in the following code:if (!newptr) exitApp("Out of Memory"); newptr->string = strdup(string);Signed-off-by Nicolas Iooss <[email protected]>
I applied these six patches.
Thanks,
Jim
Quoted 18 lines
--- restorecond/restorecond.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)restorecond/restorecond.h +1
-1@@ -33,7 +33,7 @@ extern int run_as_user;extern int start (void );extern int server (int ,const char *watch_file); -extern void exitApp (const char *msg); +extern void exitApp (const char *msg) __attribute__((__noreturn__));extern void read_config (int fd,const char *watch_file);extern int watch (int fd,const char *watch_file);
Signature · 2 lines
James Carter <[email protected]> National Security Agency