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