All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ivan Gyurdiev <ivg2@cornell.edu>
To: selinux@tycho.nsa.gov
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Subject: [ SEMANAGE ] Fix MLS parsing of users
Date: Mon, 31 Oct 2005 23:24:59 -0500	[thread overview]
Message-ID: <4366EE1B.1060303@cornell.edu> (raw)

[-- Attachment #1: Type: text/plain, Size: 713 bytes --]

Okay, I hadn't really tested MLS users very well. This patch corrects 
that oversight, and makes commit() pass on an MLS/MCS enabled system.

Changes:

- parse_filter_space_until is hopelessly broken - there's at least 2 
segfault bugs in it - delete the whole function, and handle MLS for 
users the same way I handle it for seusers - disallow multiline and 
spaces. This whole approach of looking for the "range" substring at the 
end is wrong in the first place, and genusers shouldn't be using it. 
Maybe I'll implement this properly in the future, but right now it 
doesn't seem too important - will keep MLS without spaces on a single line.

- the check whether "level" is present is backwards - fix it





[-- Attachment #2: libsepol.fix_mls_users.diff --]
[-- Type: text/x-patch, Size: 4547 bytes --]

diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsemanage/src/parse_utils.c new/libsemanage/src/parse_utils.c
--- old/libsemanage/src/parse_utils.c	2005-10-31 22:31:55.000000000 -0500
+++ new/libsemanage/src/parse_utils.c	2005-10-31 23:04:25.000000000 -0500
@@ -151,7 +151,8 @@ int parse_assert_noeof(
 	parse_info_t* info) {
 
 	if (!info->ptr) {
-		ERR(handle, "unexpected end of file");
+		ERR(handle, "unexpected end of file (%s: %u)",
+			info->filename, info->lineno);
 		return STATUS_ERR;
 	}
 
@@ -233,59 +234,6 @@ int parse_optional_str(parse_info_t* inf
 	}
 }
 
-char* parse_filter_space_until(
-	semanage_handle_t* handle, 
-	parse_info_t* info, 
-	const char* substr) {
-
-	char* buffer = NULL, *wr, *tmp;
-	int len = strlen(substr);
-	int used = 0;
-	int csize = 0;
-
-	wr = buffer;
-	do {
-		/* If content is not a space, copy to buffer */
-		if (!isspace(info->ptr)) {
-
-			/* If we're out of space, increase by 15 */
-			if (used + 1 >= csize) {
-				csize += 15;
-				tmp = realloc(buffer, csize);
-				if (!tmp)
-					goto omem;
-				buffer = tmp;
-			}
-			*wr++ = *info->ptr;
-			used++;
-		}
-		info->ptr++;
-
-		if (parse_skip_space(handle, info) < 0)
-			goto err;
-		if (parse_assert_noeof(handle, info) < 0)
-			goto err;
-
-	} while(!strncasecmp(info->ptr, substr, len));
-
-	if (!buffer) {
-		buffer = malloc(1);
-		if (!buffer)
-			goto omem;
-	}
-
-	*wr = '\0';
-
-	return buffer;
-
-	omem:
-	ERR(handle, "out of memory, could not allocate buffer");
-
-	err:
-	free(buffer);
-	return NULL;
-}
-
 int parse_fetch_string(
 	semanage_handle_t* handle,
 	parse_info_t* info, 
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsemanage/src/parse_utils.h new/libsemanage/src/parse_utils.h
--- old/libsemanage/src/parse_utils.h	2005-10-31 21:52:14.000000000 -0500
+++ new/libsemanage/src/parse_utils.h	2005-10-31 22:53:40.000000000 -0500
@@ -83,15 +83,6 @@ extern int parse_optional_str(
 	parse_info_t* info, 
 	const char* str);
 
-/* Buffer a string, filtering all 
- * whitespace, until substring is encountered,
- * at which point return the buffered string.
- * This function will work on multiple lines */
-extern char* parse_filter_space_until(
-	semanage_handle_t* handle,
-	parse_info_t* info,
-	const char* substr);
-
 /* Extract the next string (delimited by 
  * whitespace), and move the read pointer past it */
 extern int parse_fetch_string(
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsemanage/src/users_file.c new/libsemanage/src/users_file.c
--- old/libsemanage/src/users_file.c	2005-10-31 22:31:56.000000000 -0500
+++ new/libsemanage/src/users_file.c	2005-10-31 23:04:38.000000000 -0500
@@ -70,7 +70,7 @@ static int user_parse(
 	semanage_user_t* user) {
 
 	int islist = 0;
-	char* mls = NULL;
+	char* str = NULL;
 	char* start;
 	char* name_str = NULL;
 
@@ -164,35 +164,39 @@ static int user_parse(
 			goto err;
 		if (parse_assert_noeof(handle, info) < 0)
 			goto err;
-		if (parse_optional_str(info, "level") != STATUS_NODATA)
+		if (parse_optional_str(info, "level") == STATUS_NODATA)
 			goto semicolon;
 		if (parse_assert_space(handle, info) < 0)
 			goto err;
 		if (parse_assert_noeof(handle, info) < 0)
 			goto err;
 
-		mls = parse_filter_space_until(handle, info, "range");
-		if (!mls)
+		/* NOTE: does not allow spaces/multiline */
+		if (parse_fetch_string(handle, info, &str) < 0)
 			goto err;
-		if (semanage_user_set_mlslevel(handle, user, mls) < 0)
+		if (semanage_user_set_mlslevel(handle, user, str) < 0)
 			goto err;
-		free(mls);
+		free(str);
+		str = NULL;
 
 		/* Parse range header */
+		if (parse_assert_space(handle, info) < 0)
+			goto err;
 		if (parse_assert_str(handle, info, "range") < 0)
-                       goto err;
-
+			goto err;
 		if (parse_assert_space(handle, info) < 0)
 			goto err;
 		if (parse_assert_noeof(handle, info) < 0)
 			goto err;
 
-		mls = parse_filter_space_until(handle, info, ";");
-		if (!mls)
+		/* NOTE: does not allow spaces/multiline */
+		if (parse_fetch_string_until(handle, info, &str, ';') < 0)
 			goto err;
-		if (semanage_user_set_mlsrange(handle, user, mls) < 0)
+		if (semanage_user_set_mlsrange(handle, user, str) < 0)
 			goto err;
-		free(mls);
+
+		free(str);
+		str = NULL;
 	}
 
 	/* Check for semicolon */
@@ -213,7 +217,7 @@ static int user_parse(
 
 	err:
 	ERR(handle, "could not parse user record");
-	free(mls);
+	free(str);
 	parse_dispose_line(info);
 	return STATUS_ERR;
 }

             reply	other threads:[~2005-11-01  4:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-01  4:24 Ivan Gyurdiev [this message]
2005-11-01  4:38 ` [ SEMANAGE ] Fix MLS parsing of users Ivan Gyurdiev
2005-11-01  5:59   ` [ SEMANAGE ] Some seusers mapping validation Ivan Gyurdiev
2005-11-01  6:03     ` Ivan Gyurdiev
2005-11-01 17:17       ` Stephen Smalley
2005-11-01 19:50     ` Stephen Smalley
2005-11-02  8:20       ` Ivan Gyurdiev
2005-11-01 21:24     ` Stephen Smalley
2005-11-01 17:16   ` [ SEMANAGE ] Fix MLS parsing of users Stephen Smalley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4366EE1B.1060303@cornell.edu \
    --to=ivg2@cornell.edu \
    --cc=sds@tycho.nsa.gov \
    --cc=selinux@tycho.nsa.gov \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.