Skip to contentSkip to conversation

Fix fcontext comparator

SEMANAGE Ivan Gyurdiev 2 participants 2 messages Jan 6, 2006 – Jan 9, 2006 SELinux security module

lore
Share & tools
lore
#0 lore raw

The comparator for fcontext is wrong.
This should fix the problem Dan is having with the fcontext exists function - let me know if it works.

libsemanage/src/fcontext_record.c +24 -4
diff -Naurp --exclude ports_local.c --exclude-from excludes old/libsemanage/src/fcontext_record.c new/libsemanage/src/fcontext_record.c
@@ -81,8 +81,18 @@ int semanage_fcontext_compare(
 	const semanage_fcontext_t* fcontext, 
 	const semanage_fcontext_key_t* key) {
 
-	return strcmp(fcontext->expr, key->expr) && 
-		(fcontext->type == key->type);
+	int rv = strcmp(fcontext->expr, key->expr);
+	if (rv != 0)
+		return rv;
+	else {
+		if (fcontext->type < key->type)	
+			return -1;
+	
+		else if (key->type < fcontext->type)
+			return 1;
+	
+		else return 0;
+	}
 }
 hidden_def(semanage_fcontext_compare)
 
@@ -90,8 +100,18 @@ int semanage_fcontext_compare2(
 	const semanage_fcontext_t* fcontext,
 	const semanage_fcontext_t* fcontext2) {
 
-	return strcmp(fcontext->expr, fcontext2->expr) &&
-		(fcontext->type == fcontext2->type);
+	int rv = strcmp(fcontext->expr, fcontext2->expr);
+	if (rv != 0)
+		return rv;
+	else {
+		if (fcontext->type < fcontext2->type)
+			return -1;
+
+		else if (fcontext2->type < fcontext->type)
+			return 1;
+
+		else return 0;
+	}
 }
 hidden_def(semanage_fcontext_compare2)
 
#1 lore raw
Quoted 3 lines · Ivan Gyurdiev

The comparator for fcontext is wrong.
This should fix the problem Dan is having with the fcontext exists function - let me know if it works.

Merged as of libsemanage 1.5.11.

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.