Blame 0010-install-dracut-install.c-Deal-gracefully-with-paths-.patch

Harald Hoyer 7e00d9
From f9c7788ba5bbb9785ba9946c7a6500fc0c782244 Mon Sep 17 00:00:00 2001
Harald Hoyer 7e00d9
From: Colin Guthrie <colin@mageia.org>
Harald Hoyer 7e00d9
Date: Tue, 14 Aug 2012 22:32:00 +0100
Harald Hoyer 7e00d9
Subject: [PATCH] install/dracut-install.c: Deal gracefully with paths
Harald Hoyer 7e00d9
 containing double /'s
Harald Hoyer 7e00d9
Harald Hoyer 7e00d9
While such paths should not be included internally, we cannot
Harald Hoyer 7e00d9
guarantee that external scripts with shebangs will not do this.
Harald Hoyer 7e00d9
Harald Hoyer 7e00d9
Some older versions of plymouth also resulted in double /'s
Harald Hoyer 7e00d9
in some paths, so best deal with this gracefully.
Harald Hoyer 7e00d9
---
Harald Hoyer 7e00d9
 install/dracut-install.c | 10 ++++++++--
Harald Hoyer 7e00d9
 1 file changed, 8 insertions(+), 2 deletions(-)
Harald Hoyer 7e00d9
Harald Hoyer 7e00d9
diff --git a/install/dracut-install.c b/install/dracut-install.c
Harald Hoyer 7e00d9
index 9a244ba..dfee259 100644
Harald Hoyer 7e00d9
--- a/install/dracut-install.c
Harald Hoyer 7e00d9
+++ b/install/dracut-install.c
Harald Hoyer 7e00d9
@@ -64,7 +64,7 @@ static size_t dir_len(char const *file)
Harald Hoyer 7e00d9
         size_t length;
Harald Hoyer 7e00d9
         /* Strip the basename and any redundant slashes before it.  */
Harald Hoyer 7e00d9
         for (length = strlen(file); 0 < length; length--)
Harald Hoyer 7e00d9
-                if (file[length] == '/')
Harald Hoyer 7e00d9
+                if (file[length] == '/' && file[length-1] != '/')
Harald Hoyer 7e00d9
                         break;
Harald Hoyer 7e00d9
         return length;
Harald Hoyer 7e00d9
 }
Harald Hoyer 7e00d9
@@ -91,7 +91,13 @@ static char *convert_abs_rel(const char *from, const char *target)
Harald Hoyer 7e00d9
                 return strdup(from);
Harald Hoyer 7e00d9
         }
Harald Hoyer 7e00d9
 
Harald Hoyer 7e00d9
-        asprintf(&realtarget, "%s/%s", q, &p[dirlen + 1]);
Harald Hoyer 7e00d9
+        /* dir_len() skips double /'s e.g. //lib64, so we can't skip just one
Harald Hoyer 7e00d9
+         * character - need to skip all leading /'s */
Harald Hoyer 7e00d9
+        rl = strlen(target);
Harald Hoyer 7e00d9
+        for (i = dirlen+1; i < rl; ++i)
Harald Hoyer 7e00d9
+            if (p[i] != '/')
Harald Hoyer 7e00d9
+                break;
Harald Hoyer 7e00d9
+        asprintf(&realtarget, "%s/%s", q, &p[i]);
Harald Hoyer 7e00d9
         free(p);
Harald Hoyer 7e00d9
         free(q);
Harald Hoyer 7e00d9