Skip to contentSkip to conversation

Assert whitespace between records

SEMANAGE Ivan Gyurdiev 2 participants 2 messages Nov 4, 2005 SELinux security module

lore
Share & tools
lore
#0 lore raw

This patch will assert there is whitespace between seuser, boolean, interface, and port records (assert whitespace after each record). This has no effect on ports and interfaces, because they already check for that when looking for where the context ends (added for clarity only). Users don't require a space, because they have a semicolon.

In the case of seusers, this prevents parser confusion when MLS is disabled, and we encounter an MLS context:
a:b:c - complain about lack of whitespace, rather than treating the ":" as the next seuser, and saying something like: nonempty string expected, or whatever...

In the case of booleans, this change will consider a=TRUEb=false or things like that as a parse error.

This change will succeed on the last record, and at the end of each line, because the terminating '\0' is considered whitespace - it's present on all lines, including the last one. It will not succeed if you called skip_space right before that, because that zeros the buffer on EOF (intentionally).

libselinux/src/seusers.c +3 -3
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libselinux/src/seusers.c new/libselinux/src/seusers.c
@@ -45,7 +45,6 @@ static int process_seusers(const char *b
 	if (!end) {
 		mls_found = 0;
 
-		/* MLS is disabled, so :level suffix not required. */
 		end = start;
 		while (*end && !isspace(*end))
 			end++;
@@ -55,9 +54,10 @@ static int process_seusers(const char *b
 	seuser = strdup(start);
 	if (!seuser)
 		goto err;
-
+	
+	/* Skip MLS if disabled, or missing. */
 	if (!mls_enabled || !mls_found)
-		goto out; /* skip any MLS level */
+		goto out;
 
 	start = ++end;
 	while (*end && !isspace(*end))
libsemanage/src/booleans_file.c +3 -0
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsemanage/src/booleans_file.c new/libsemanage/src/booleans_file.c
@@ -87,6 +87,9 @@ static int bool_parse(
 	}
 	semanage_bool_set_value(boolean, value);
 
+	if (parse_assert_space(handle, info) < 0)
+		goto err;
+
 	return STATUS_SUCCESS;
 
 	last:
libsemanage/src/interfaces_file.c +3 -0
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsemanage/src/interfaces_file.c new/libsemanage/src/interfaces_file.c
@@ -127,6 +127,9 @@ static int iface_parse(
 	semanage_iface_set_msgcon(iface, con);
 	con = NULL;
 
+	if (parse_assert_space(handle, info) < 0)
+		goto err;
+
 	return STATUS_SUCCESS;
 
 	last:
libsemanage/src/ports_file.c +3 -0
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsemanage/src/ports_file.c new/libsemanage/src/ports_file.c
@@ -134,6 +134,9 @@ static int port_parse(
 	semanage_port_set_con(port, con);
 	con = NULL;
 
+	if (parse_assert_space(handle, info) < 0)
+		goto err;
+
 	return STATUS_SUCCESS;
 
 	last:
libsemanage/src/seusers_file.c +4 -1
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsemanage/src/seusers_file.c new/libsemanage/src/seusers_file.c
@@ -96,7 +96,10 @@ static int seuser_parse(
 			goto err;
 		free(str);
 		str = NULL;
-	} 
+	}
+
+	if (parse_assert_space(handle, info) < 0)
+		goto err; 
 	
 	out:
 	return STATUS_SUCCESS;
#1 lore raw
Quoted 12 lines · Ivan Gyurdiev

This patch will assert there is whitespace between seuser, boolean, interface, and port records (assert whitespace after each record). This has no effect on ports and interfaces, because they already check for that when looking for where the context ends (added for clarity only). Users don't require a space, because they have a semicolon.

In the case of seusers, this prevents parser confusion when MLS is disabled, and we encounter an MLS context:
a:b:c - complain about lack of whitespace, rather than treating the ":" as the next seuser, and saying something like: nonempty string expected, or whatever...

Quoted 8 lines

In the case of booleans, this change will consider a=TRUEb=false or things like that as a parse error.

This change will succeed on the last record, and at the end of each line, because the terminating '\0' is considered whitespace - it's present on all lines, including the last one. It will not succeed if you called skip_space right before that, because that zeros the buffer on EOF (intentionally).

Ok. But I think we also want something like the patch below in the libselinux case to handle an empty seuser or level field as an error condition.

Index: libselinux/src/seusers.c
===================================================================
RCS file: /nfshome/pal/CVS/selinux-usr/libselinux/src/seusers.c,v retrieving revision 1.9

src/seusers.c +6 -0
diff -u -p -r1.9 seusers.c
@@ -54,6 +54,9 @@ static int process_seusers(const char *b
 	seuser = strdup(start);
 	if (!seuser)
 		goto err;
+
+	if (!strcmp(seuser, ""))
+		goto err;
 	
 	/* Skip MLS if disabled, or missing. */
 	if (!mls_enabled || !mls_found)
@@ -68,6 +71,9 @@ static int process_seusers(const char *b
 	if (!level)
 		goto err;
 
+	if (!strcmp(level, ""))
+		goto err;
+
 out:
 	free(newbuf);
 	*luserp = luser;
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.