Skip to contentSkip to conversation

Don't free n[i] when n is NULL

PATCH New [email protected] 1 participant 1 message Aug 10, 2005 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Don't free n[i] when n is NULL

This patch fixes a bug found in booleans.c by Coverity:

When the malloc for n fails, we jump to 'bad:', where we proceed to try to free n[i] even though n is NULL.

booleans.c +3 -2
Index: src/booleans.c
===================================================================
@@ -70,7 +70,7 @@ int security_get_boolean_names(char ***n
 				     * (namelist[i]->d_reclen + 1));
 		if (!n[i]) {
 			rc = -1;
-			goto bad;
+			goto bad_freen;
 		}
 		strncpy(n[i], namelist[i]->d_name, namelist[i]->d_reclen + 1);
 	}
@@ -82,12 +82,13 @@ out:
 	}
 	free(namelist);
 	return rc;
-bad:
+bad_freen:
 	for (i = 0; i < *len; i++) {
 		if (n[i])
 			free(n[i]);
 	}
 	free(n);
+bad:
 	goto out;
 }
 

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.