Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 3 Aug 2002 07:51:39 -0700 (PDT)
From:      Robert Watson <rwatson@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 15484 for review
Message-ID:  <200208031451.g73Epd98091566@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://people.freebsd.org/~peter/p4db/chv.cgi?CH=15484

Change 15484 by rwatson@rwatson_curry on 2002/08/03 07:51:32

	Prod a bit at the userland MAC library to accept partial MAC
	labels in which not all policies are present, and to print
	partial labels without policies with null labels.

Affected files ...

.. //depot/projects/trustedbsd/mac/lib/libc/posix1e/mac_te.c#5 edit
.. //depot/projects/trustedbsd/mac/lib/libc/posix1e/mac_text.c#22 edit

Differences ...

==== //depot/projects/trustedbsd/mac/lib/libc/posix1e/mac_te.c#5 (text+ko) ====

@@ -54,8 +54,6 @@
 {
 
 	bzero(&label->m_te, sizeof(label->m_te));
-	if (strlen(string) == 0)
-		return (EINVAL);
 	if (strlcpy(label->m_te.mt_type, string,
 	    sizeof(label->m_te.mt_type)) >= sizeof(label->m_te.mt_type))
 		return (EINVAL);

==== //depot/projects/trustedbsd/mac/lib/libc/posix1e/mac_text.c#22 (text+ko) ====

@@ -68,7 +68,7 @@
 mac_to_text(struct mac *mac_p, size_t *len_p)
 {
 	char *biba = NULL, *mls = NULL, *string = NULL, *te = NULL;
-	int len = -1;
+	int len = -1, before;
 
 	biba = mac_biba_string_from_label(mac_p);
 	if (biba == NULL)
@@ -82,10 +82,49 @@
 	if (te == NULL)
 		goto out;
 
-	len = asprintf(&string, "%s%s%s%s%s%s%s%s%s%s%s",
-	    STRING_BIBA, STRING_ELEMENTSEP, biba, STRING_LISTSEP,
-	    STRING_MLS, STRING_ELEMENTSEP, mls, STRING_LISTSEP,
-	    STRING_TE, STRING_ELEMENTSEP, te);
+	len = 0;
+	if (strlen(biba) != 0)
+		len += strlen(STRING_LISTSEP) + strlen(STRING_BIBA) +
+		    strlen(STRING_ELEMENTSEP) + strlen(biba);
+	if (strlen(mls) != 0)
+		len += strlen(STRING_LISTSEP) + strlen(STRING_MLS) +
+		    strlen(STRING_ELEMENTSEP) + strlen(mls);
+	if (strlen(te) != 0)
+		len += strlen(STRING_LISTSEP) + strlen(STRING_TE) +
+		    strlen(STIRNG_ELEMENTSEP) + strlen(te);
+
+	if (len == 0) {
+		string = strdup("");
+		goto out;
+	}
+
+	string = (char *) malloc(len+1);
+	if (string == NULL)
+		return (NULL);
+
+	len = 0;
+
+	if (strlen(biba) != 0) {
+		if (before)
+			len += sprintf(string + len, "%s", STRING_LISTSEP);
+		len += sprintf(string + len, "%s%s%s", STRING_BIBA,
+		    STRING_ELEMENTSEP, biba);
+		before = 1;
+	}
+	if (strlen(mls) != 0) {
+		if (before)
+			len += sprintf(string + len, "%s", STRING_LISTSEP);
+		len += sprintf(string + len, "%s%s%s", STRING_MLS,
+		    STRING_ELEMENTSEP, mls);
+		before = 1;
+	}
+	if (strlen(te) != 0) {
+		if (before)
+			len += sprintf(string + len, "%s", STRING_LISTSEP);
+		len += sprintf(string + len, "%s%s%s", STRING_TE,
+		    STRING_ELEMENTSEP, te);
+		before = 1;
+	}
 
 out:
 	if (biba != NULL)
@@ -165,7 +204,29 @@
 		}
 	}
 
-	if (biba_seen != 1 || mls_seen != 1 || te_seen != 1) {
+	if (biba_seen == 0) {
+		error = mac_biba_label_from_string("", label);
+		if (error) {
+			errno = error;
+			goto exit2;
+		}
+	}
+	if (mls_seen == 0) {
+		error = mac_mls_label_from_string("", label);
+		if (error) {
+			errno = error;
+			goto exit2;
+		}
+	}
+	if (te_seen == 0) {
+		error = mac_te_label_from_string("", label);
+		if (error) {
+			errno = error;
+			goto exit2;
+		}
+	}
+
+	if (biba_seen > 1 || mls_seen > 1 || te_seen > 1) {
 		errno = EINVAL;
 		goto exit2;
 	}

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe p4-projects" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200208031451.g73Epd98091566>