Miscellaneous cleanups
Remove unused ret variable causing confusion.
Simplify handling of strdup failure - the only reason strdup will fail is OMEM, in which case there's no reason to go into detail regarding exactly which boolean failed.
policycoreutils/setsebool/setsebool.c +13 -18
@@ -173,16 +173,14 @@ static int semanage_set_boolean_list(int setbool (char **list,size_t start,size_t end) {char *name, *value_ptr; -int ret=0 , j=0 , value; +int j=0 , value;size_t i = start;size_t boolcnt=end-start;struct passwd *pwd;SELboolean *vallist=calloc (boolcnt,sizeof (SELboolean)); -if (!vallist) { -fprintf (stderr, -"Error setting booleans: %s\n" ,strerror (errno)); -return 1 ; - } +if (!vallist) + goto omem; +while (i < end) { name = list[i]; value_ptr =strchr (list[i],'=' );
@@ -190,7 +188,6 @@ int setbool(char **list, size_t start, sfprintf (stderr,"setsebool: '=' not found in boolean expression %s\n" , list[i]); - ret=4 ; goto err; } *value_ptr =0 ;
@@ -202,21 +199,16 @@ int setbool(char **list, size_t start, s strcasecmp(value_ptr, "false") == 0) value = 0; else { -fprintf (stderr,"setsebool: illegal boolean value %s\n" , - value_ptr); - ret=1 ; +fprintf (stderr,"setsebool: illegal value " +"%s for boolean %s\n" , + value_ptr, name); goto err; } vallist[j].value = value; vallist[j].name =strdup (name); -if (!vallist[j].name) { -fprintf (stderr, -"Error setting boolean %s to value %d (%s)\n" , - name, value,strerror (errno)); - ret=2 ; - goto err; - } +if (!vallist[j].name) + goto omem; i++; j++;
@@ -257,7 +249,10 @@ int setbool(char **list, size_t start, sfree (vallist[i].name);free (vallist);return 0 ; - + + omem: +fprintf (stderr,"setsebool: out of memory" ); + err:for (i=0 ; i < boolcnt; i++)free (vallist[i].name);