- stable sort for policy specifications, patterns before paths.
authorjbj <devnull@localhost>
Sun, 22 Feb 2004 23:43:05 +0000 (23:43 +0000)
committerjbj <devnull@localhost>
Sun, 22 Feb 2004 23:43:05 +0000 (23:43 +0000)
CVS patchset: 7121
CVS date: 2004/02/22 23:43:05

CHANGES
lib/rpmsx.c
rpm.spec.in

diff --git a/CHANGES b/CHANGES
index 2c633fd..f15ade2 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -20,6 +20,7 @@
        - establish rpm_script_t before scriptlet exec.
        - python: add patch to rpm-4_3 to initialize RE contexts.
        - fix: only first "mkdir -p" directory had context set.
+       - stable sort for policy specifications, patterns before paths.
 
 4.2.1 -> 4.2.2:
        - unify signal handling in librpmio, use condvar to deliver signal.
index a61ccaa..f45b7f8 100644 (file)
 int _rpmsx_debug = 0;
 
 /**
- */
-static int rpmsxpCompare(const void* A, const void* B)
-       /*@*/
-{
-    rpmsxp sxpA = (rpmsxp) A;
-    rpmsxp sxpB = (rpmsxp) B;
-    return (sxpB->hasMetaChars - sxpA->hasMetaChars);
-}
-
-/**
- * Sort the specifications with most general first.
+ * Stable sort for policy specifications, patterns before paths.
  * @param sx           security context patterns
  */
 static void rpmsxSort(rpmsx sx)
        /*@modifies sx @*/
 {
-    qsort(sx->sxp, sx->Count, sizeof(*sx->sxp), rpmsxpCompare);
+    rpmsxp sxp;
+    int i, j;
+
+    /* Stable sort for policy regex's and paths. */
+    sxp = xmalloc(sizeof(*sxp) * sx->Count);
+
+    /* Regex patterns first ... */
+    j = 0;
+    for (i = 0; i < sx->Count; i++) {
+       if (!sx->sxp[i].hasMetaChars)
+           continue;
+       memcpy(sxp + j, sx->sxp + i, sizeof(*sxp));
+       j++;
+    }
+
+    /* ... then file paths. */
+    for (i = 0; i < sx->Count; i++) {
+       if (sx->sxp[i].hasMetaChars)
+           continue;
+       memcpy(sxp + j, sx->sxp + i, sizeof(*sxp));
+       j++;
+    }
+
+    sx->sxp = _free(sx->sxp);
+    sx->sxp = sxp;
 }
 
 /* Determine if the regular expression specification has any meta characters. */
@@ -308,6 +322,7 @@ int rpmsxParse(rpmsx sx, const char * fn)
     int pass;
     int regerr;
     int nerr = 0;
+    
 #define        inc_err()       nerr++
 
 /*@-branchstate@*/
@@ -467,7 +482,7 @@ int rpmsxParse(rpmsx sx, const char * fn)
 /*@=branchstate@*/
     (void) fclose(fp);
 
-    /* Sort the specifications with most general first */
+   /* Stable sort for policy specifications, patterns before paths. */
     rpmsxSort(sx);
 
     /* Verify no exact duplicates */
index e357a6e..6f482f4 100644 (file)
@@ -484,6 +484,7 @@ exit 0
 %changelog
 * Sun Feb 22 2004 Jeff Johnson <jbj@jbj.org> 4.3-0.14
 - add ia32e arch.
+- stable sort for policy specifications, patterns before paths.
 
 * Fri Feb 20 2004 Jeff Johnson <jbj@jbj.org> 4.3-0.13
 - fix: only first "mkdir -p" directory had context set.