Skip to contentSkip to conversation

libselinux: avoid NULL deref

PATCH In review [email protected] 2 participants 3 messages Aug 24, 2005 – Aug 25, 2005 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libselinux: avoid NULL deref

This patch fixes a bug found by Coverity in setsetbool.c.

After these two patches I sent today, the only bugs I'm finding are 1 false positive in libsemanage, and 22 unchecked in libsepol.

thanks,
-serge

setsebool.c renamed from setsebool.c.orig +7 -0
@@ -154,6 +154,13 @@ int setbool(char **list, size_t start, s
 		   this above and aborted if something went wrong. */
 		name = list[i];
 		value_ptr = strchr(name, '=');
+		if (!value_ptr) {
+			syslog(LOG_NOTICE,
+				"Malformed entry for boolean %s\n",
+				name);
+			i++;
+			continue;
+		}
 		*value_ptr = 0;
 		value_ptr++;
 		if (pwd && pwd->pw_name)

--
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.

#1 lore raw
Quoted 14 lines · On Wed, 2005-08-24 at 13:28 -0500, [email protected] wrote:

This patch fixes a bug found by Coverity in setsetbool.c.

After these two patches I sent today, the only bugs I'm finding are 1 false positive in libsemanage, and 22 unchecked in libsepol.

thanks,

(quoted diff) +0 -1
-serge
setsebool.c renamed from setsebool.c.orig +0 -0
@@ -154,6 +154,13 @@ int setbool(char **list, size_t start, s
 		   this above and aborted if something went wrong. */
 		name = list[i];
 		value_ptr = strchr(name, '=');

setsebool.c int setbool(char **list, size_t start, s · line 166

Quoted 10 lines
setsebool.c renamed from setsebool.c.orig +7 -0
+		if (!value_ptr) {
+			syslog(LOG_NOTICE,
+				"Malformed entry for boolean %s\n",
+				name);
+			i++;
+			continue;
+		}
 		*value_ptr = 0;
 		value_ptr++;
 		if (pwd && pwd->pw_name)

The immediately preceding comment says:
/* Error checking shouldn't be needed since we just did
this above and aborted if something went wrong. */
And looking at the code flow, it would have bailed prior to reaching this code if the strchr had failed at all on the first pass, right?

Signature · 8 lines
Stephen Smalley
National Security Agency


--
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.
#2 lore raw
Quoted 23 lines · Stephen Smalley
Quoted 22 lines · On Wed, 2005-08-24 at 13:28 -0500, [email protected] wrote:

This patch fixes a bug found by Coverity in setsetbool.c.

After these two patches I sent today, the only bugs I'm finding are 1 false positive in libsemanage, and 22 unchecked in libsepol.

thanks,

(quoted diff) +0 -1
-serge
setsebool.c renamed from setsebool.c.orig +7 -0
@@ -154,6 +154,13 @@ int setbool(char **list, size_t start, s
 		   this above and aborted if something went wrong. */
 		name = list[i];
 		value_ptr = strchr(name, '=');
+		if (!value_ptr) {
+			syslog(LOG_NOTICE,
+				"Malformed entry for boolean %s\n",
+				name);
+			i++;
+			continue;
+		}
 		*value_ptr = 0;
Quoted 8 lines

setsebool.c int setbool(char **list, size_t start, s · line 166

Quoted 2 lines
setsebool.c renamed from setsebool.c.orig +0 -0
 		value_ptr++;
 		if (pwd && pwd->pw_name)

The immediately preceding comment says:
/* Error checking shouldn't be needed since we just did
this above and aborted if something went wrong. */
And looking at the code flow, it would have bailed prior to reaching this code if the strchr had failed at all on the first pass, right?

Oh, that's right. That's why I had ignored it in previous runs!

Please disregard...

thanks,
-serge

--
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.