bug-patch
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-patch] [PATCH] do not validate target name when it is specified on


From: Jim Meyering
Subject: [bug-patch] [PATCH] do not validate target name when it is specified on the command line
Date: Thu, 10 Feb 2011 13:19:54 +0100

Tim Waugh reported this problem.
There are several ways to fix it...
Here's one:

2011-02-10  Jim Meyering  <address@hidden>

        do not validate target name when it is specified on the command line
        To do that, we want to make validate_target_name return immediately
        when the patch.c-scoped global, explicit_inname, is true.
        However, validate_target_name is in pch.c, so...
        * src/pch.c (validate_target_name): Move function to ...
        * src/patch.c (validate_target_name): ...here, and make it return
        immediately when explicit_inname is set.
        Include dirname.h.
        * src/common.h (validate_target_name): Declare it.
        * tests/bad-filenames: Add a test for this.
        Reported by Tim Waugh in http://bugzilla.redhat.com/667529#c21


>From 9ff93df7ccf9c3a35e9b383938a48c3b51fb73aa Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Thu, 10 Feb 2011 13:16:17 +0100
Subject: [PATCH] do not validate target name when it is specified on the 
command line

To do that, we want to make validate_target_name return immediately
when the patch.c-scoped global, explicit_inname, is true.
However, validate_target_name is in pch.c, so...
* src/pch.c (validate_target_name): Move function to ...
* src/patch.c (validate_target_name): ...here, and make it return
immediately when explicit_inname is set.
Include dirname.h.
* src/common.h (validate_target_name): Declare it.
* tests/bad-filenames: Add a test for this.
Reported by Tim Waugh in http://bugzilla.redhat.com/667529#c21
---
 ChangeLog           |   14 ++++++++++++++
 src/common.h        |    1 +
 src/patch.c         |   21 +++++++++++++++++++++
 src/pch.c           |   18 ------------------
 tests/bad-filenames |    8 ++++++++
 5 files changed, 44 insertions(+), 18 deletions(-)

diff --git a/src/common.h b/src/common.h
index b38f1b2..8e8486e 100644
--- a/src/common.h
+++ b/src/common.h
@@ -143,6 +143,7 @@ XTERN char *revision;                       /* prerequisite 
revision, if any */
 #endif

 void fatal_exit (int) __attribute__ ((noreturn));
+void validate_target_name (char const *n);

 #include <errno.h>
 #if !STDC_HEADERS && !defined errno
diff --git a/src/patch.c b/src/patch.c
index 21740c9..f07fafb 100644
--- a/src/patch.c
+++ b/src/patch.c
@@ -31,6 +31,7 @@
 #include <util.h>
 #include <version.h>
 #include <xalloc.h>
+#include <dirname.h>

 /* procedures */

@@ -1015,6 +1016,26 @@ numeric_string (char const *string,
   return value;
 }

+void
+validate_target_name (char const *n)
+{
+  char const *p = n;
+  if (explicit_inname)
+    return;
+  if (IS_ABSOLUTE_FILE_NAME (p))
+    fatal ("rejecting absolute target file name: %s", quotearg (p));
+  while (*p)
+    {
+      if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
+       fatal ("rejecting target file name with \"..\" component: %s",
+              quotearg (n));
+      while (*p && ! ISSLASH (*p))
+       p++;
+      while (ISSLASH (*p))
+       p++;
+    }
+}
+
 /* Attempt to find the right place to apply this hunk of patch. */

 static lin
diff --git a/src/pch.c b/src/pch.c
index f661b69..bdfe0d4 100644
--- a/src/pch.c
+++ b/src/pch.c
@@ -189,24 +189,6 @@ grow_hunkmax (void)
     return false;
 }

-static void
-validate_target_name (char const *n)
-{
-  char const *p = n;
-  if (IS_ABSOLUTE_FILE_NAME (p))
-    fatal ("rejecting absolute target file name: %s", quotearg (p));
-  while (*p)
-    {
-      if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p)))
-       fatal ("rejecting target file name with \"..\" component: %s",
-              quotearg (n));
-      while (*p && ! ISSLASH (*p))
-       p++;
-      while (ISSLASH (*p))
-       p++;
-    }
-}
-
 static bool
 maybe_reverse (char const *name, bool nonexistent, bool is_empty)
 {
diff --git a/tests/bad-filenames b/tests/bad-filenames
index 00e6533..44d02ba 100644
--- a/tests/bad-filenames
+++ b/tests/bad-filenames
@@ -61,3 +61,11 @@ check 'emit_2 /abs/path target | patch -R -p0; echo status: 
$?' <<EOF
 patching file target
 status: 0
 EOF
+
+# Do not validate any file name from the input when the target
+# is specified on the command line:
+touch abs
+check 'emit_patch /absolute/path | patch `pwd`/abs; echo status: $?' <<EOF
+patching file `pwd`/abs
+status: 0
+EOF
--
1.7.4.19.ga8e4a



reply via email to

[Prev in Thread] Current Thread [Next in Thread]