Igor Gnatenko 082d5d
From faaf3bbfc261f49eda996801b50996fb1066092f Mon Sep 17 00:00:00 2001
Igor Gnatenko 082d5d
From: Mark Wielaard <mark@klomp.org>
Igor Gnatenko 082d5d
Date: Wed, 28 Jun 2017 20:25:39 +0200
Igor Gnatenko 082d5d
Subject: [PATCH 39/49] debugedit: skip_dir_prefix should check for dir
Igor Gnatenko 082d5d
 separator.
Igor Gnatenko 082d5d
Igor Gnatenko 082d5d
To count as a real directory prefix the string matched should either
Igor Gnatenko 082d5d
be equal to the given prefix or start with the prefix plus '/'.
Igor Gnatenko 082d5d
Igor Gnatenko 082d5d
skip_dir_prefix is always used with base_dir or dest_dir which don't
Igor Gnatenko 082d5d
end with a slash themselves.
Igor Gnatenko 082d5d
Igor Gnatenko 082d5d
This really only is an issue if a package would put a directory named
Igor Gnatenko 082d5d
similar to the package source dir (which cargo on fedora does, by adding
Igor Gnatenko 082d5d
a directory named cargo-vendor in the builddir itself).
Igor Gnatenko 082d5d
Igor Gnatenko 082d5d
Signed-off-by: Mark Wielaard <mark@klomp.org>
Igor Gnatenko 082d5d
(cherry picked from commit 2ea5619e375f0717b755c8aa4a38254ea622b833)
Igor Gnatenko 082d5d
---
Igor Gnatenko 082d5d
 tools/debugedit.c | 10 ++++++++--
Igor Gnatenko 082d5d
 1 file changed, 8 insertions(+), 2 deletions(-)
Igor Gnatenko 082d5d
Mark Wielaard 6e205b
diff --git a/tools/debugedit.c b/tools/debugedit.c
Igor Gnatenko 082d5d
index bf115136c..682189929 100644
Mark Wielaard 6e205b
--- a/tools/debugedit.c
Mark Wielaard 6e205b
+++ b/tools/debugedit.c
Mark Wielaard 6e205b
@@ -662,7 +662,8 @@ canonicalize_path (const char *s, char *d)
Mark Wielaard 6e205b
 /* Returns the rest of PATH if it starts with DIR_PREFIX, skipping any
Mark Wielaard 6e205b
    / path separators, or NULL if PATH doesn't start with
Mark Wielaard 6e205b
    DIR_PREFIX. Might return the empty string if PATH equals DIR_PREFIX
Mark Wielaard 6e205b
-   (modulo trailing slashes). Never returns path starting with '/'. */
Mark Wielaard 6e205b
+   (modulo trailing slashes). Never returns path starting with '/'.
Mark Wielaard 6e205b
+   Note that DIR_PREFIX itself should NOT end with a '/'.  */
Mark Wielaard 6e205b
 static const char *
Mark Wielaard 6e205b
 skip_dir_prefix (const char *path, const char *dir_prefix)
Mark Wielaard 6e205b
 {
Mark Wielaard 6e205b
@@ -670,12 +671,17 @@ skip_dir_prefix (const char *path, const char *dir_prefix)
Mark Wielaard 6e205b
   if (strncmp (path, dir_prefix, prefix_len) == 0)
Mark Wielaard 6e205b
     {
Mark Wielaard 6e205b
       path += prefix_len;
Mark Wielaard 6e205b
+      /* Unless path == dir_prefix there should be at least one '/'
Mark Wielaard 6e205b
+	 in the path (which we will skip).  Otherwise the path has
Mark Wielaard 6e205b
+	 a different (longer) directory prefix.  */
Mark Wielaard 6e205b
+      if (*path != '\0' && !IS_DIR_SEPARATOR (*path))
Mark Wielaard 6e205b
+	return NULL;
Mark Wielaard 6e205b
       while (IS_DIR_SEPARATOR (path[0]))
Mark Wielaard 6e205b
 	path++;
Mark Wielaard 6e205b
       return path;
Mark Wielaard 6e205b
     }
Mark Wielaard 6e205b
 
Mark Wielaard 6e205b
-  return 0;
Mark Wielaard 6e205b
+  return NULL;
Mark Wielaard 6e205b
 }
Mark Wielaard 6e205b
 
Mark Wielaard 6e205b
 /* Most strings will be in the existing debug string table. But to
Igor Gnatenko 082d5d
-- 
Igor Gnatenko 082d5d
2.13.2
Igor Gnatenko 082d5d