bug-patch
[Top][All Lists]
Advanced

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

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


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

Andreas Gruenbacher wrote:

> On Thursday 17 February 2011 09:25:57 Jim Meyering wrote:
>> Andreas Gruenbacher wrote:
>> > On Wednesday 16 February 2011 18:03:21 Jim Meyering wrote:
>> >> Here's a better patch.
>> >
>> > Nice.  Now we can suppress warnings for equal filenames too for even fewer
>> > confusing warnings.  Here is your last patch + some coding style changes +
>> > actually comparing filenames + test case.
>>
>> Good improvements.  I usually put a space between the "!!" operator
>> and its operand, too.
>>
>> I noticed that we can avoid a useless comparison in the common case,
>
> IMO it's not worth it.
>
> Can you put the rest in, also to see if you have proper push access to the
> repo?

Sure:

>From e0f707523cab26f74ec23f4a20a27add8702ed5b Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Thu, 17 Feb 2011 09:59:56 +0100
Subject: [PATCH] don't warn twice about the same invalid file name

* src/pch.c (name_is_valid): Don't warn about the same name twice.
* tests/bad-filenames (emit_patch): Exercise the new code.
---
 ChangeLog           |    7 +++++++
 src/pch.c           |   10 +++++++++-
 tests/bad-filenames |   24 ++++++++++++++++++++++++
 3 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index defc7be..046df0e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-02-17  Jim Meyering  <address@hidden>
+       and Andreas Gruenbacher <address@hidden>
+
+       don't warn twice about the same invalid file name
+       * src/pch.c (name_is_valid): Don't warn about the same name twice.
+       * tests/bad-filenames (emit_patch): Exercise the new code.
+
 2011-02-16  Andreas Gruenbacher <address@hidden>

        * src/pch.c (name_is_valid): New function.
diff --git a/src/pch.c b/src/pch.c
index 41c15b6..1fd3848 100644
--- a/src/pch.c
+++ b/src/pch.c
@@ -379,11 +379,18 @@ skip_hex_digits (char const *str)
 static bool
 name_is_valid (char const *name)
 {
-  const char *n = name;
+  static char const *bad[2];
+  char const *n;
+
+  if (bad[0] && ! strcmp (bad[0], name))
+    return false;
+  if (bad[1] && ! strcmp (bad[1], name))
+    return false;

   if (IS_ABSOLUTE_FILE_NAME (name))
     {
       say ("Ignoring potentially dangerous file name %s\n", quotearg (name));
+      bad[!! bad[0]] = name;
       return false;
     }
   for (n = name; *n; )
@@ -391,6 +398,7 @@ name_is_valid (char const *name)
       if (*n == '.' && *++n == '.' && ( ! *++n || ISSLASH (*n)))
         {
          say ("Ignoring potentially dangerous file name %s\n", quotearg 
(name));
+         bad[!! bad[0]] = name;
          return false;
        }
       while (*n && ! ISSLASH (*n))
diff --git a/tests/bad-filenames b/tests/bad-filenames
index 0bc23eb..e1b9e92 100644
--- a/tests/bad-filenames
+++ b/tests/bad-filenames
@@ -114,3 +114,27 @@ echo 1 > g
 check 'patch -f -p1 --dry-run < d.diff || echo status: $?' <<EOF
 patching file g
 EOF
+
+mkdir d
+cd d
+cat > d.diff <<EOF
+--- ../h
++++ ../h
+@@ -0,0 +1 @@
++x
+EOF
+
+touch ../h
+check 'patch -f -p0 < d.diff || echo status: $?' <<EOF
+Ignoring potentially dangerous file name ../h
+can't find file to patch at input line 3
+Perhaps you used the wrong -p or --strip option?
+The text leading up to this was:
+--------------------------
+|--- ../h
+|+++ ../h
+--------------------------
+No file to patch.  Skipping patch.
+1 out of 1 hunk ignored
+status: 1
+EOF
--
1.7.4.1.11.g24231



reply via email to

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