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