Blame SOURCES/0133-core-namespace-fix-path-sorting.patch

17b0f1
From 0881ff2b6842798836faef3a55a04a3e6e0cbb66 Mon Sep 17 00:00:00 2001
17b0f1
From: Michal Schmidt <mschmidt@redhat.com>
17b0f1
Date: Mon, 16 Mar 2015 22:04:21 +0100
17b0f1
Subject: [PATCH] core/namespace: fix path sorting
17b0f1
17b0f1
The comparison function we use for qsorting paths is overly indifferent.
17b0f1
Consider these 3 paths for sorting:
17b0f1
 /foo
17b0f1
 /bar
17b0f1
 /foo/foo
17b0f1
qsort() may compare:
17b0f1
 "/foo" with "/bar" => 0, indifference
17b0f1
 "/bar" with "/foo/foo" => 0, indifference
17b0f1
and assume transitively that "/foo" and "/foo/foo" are also indifferent.
17b0f1
17b0f1
But this is wrong, we want "/foo" sorted before "/foo/foo".
17b0f1
The comparison function must be transitive.
17b0f1
17b0f1
Use path_compare(), which behaves properly.
17b0f1
17b0f1
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1184016
17b0f1
(cherry picked from commit a0827e2b123010c46cfe4f03eebba57d92f9efc4)
17b0f1
---
17b0f1
 src/core/namespace.c | 12 ++++--------
17b0f1
 1 file changed, 4 insertions(+), 8 deletions(-)
17b0f1
17b0f1
diff --git a/src/core/namespace.c b/src/core/namespace.c
17b0f1
index 4fecd32363..d4f1c86211 100644
17b0f1
--- a/src/core/namespace.c
17b0f1
+++ b/src/core/namespace.c
17b0f1
@@ -91,9 +91,11 @@ static int append_mounts(BindMount **p, char **strv, MountMode mode) {
17b0f1
 
17b0f1
 static int mount_path_compare(const void *a, const void *b) {
17b0f1
         const BindMount *p = a, *q = b;
17b0f1
+        int d;
17b0f1
 
17b0f1
-        if (path_equal(p->path, q->path)) {
17b0f1
+        d = path_compare(p->path, q->path);
17b0f1
 
17b0f1
+        if (!d) {
17b0f1
                 /* If the paths are equal, check the mode */
17b0f1
                 if (p->mode < q->mode)
17b0f1
                         return -1;
17b0f1
@@ -105,13 +107,7 @@ static int mount_path_compare(const void *a, const void *b) {
17b0f1
         }
17b0f1
 
17b0f1
         /* If the paths are not equal, then order prefixes first */
17b0f1
-        if (path_startswith(p->path, q->path))
17b0f1
-                return 1;
17b0f1
-
17b0f1
-        if (path_startswith(q->path, p->path))
17b0f1
-                return -1;
17b0f1
-
17b0f1
-        return 0;
17b0f1
+        return d;
17b0f1
 }
17b0f1
 
17b0f1
 static void drop_duplicates(BindMount *m, unsigned *n) {