summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2011-02-17 09:59:56 +0100
committerJim Meyering <meyering@redhat.com>2011-02-17 10:00:57 +0100
commite0f707523cab26f74ec23f4a20a27add8702ed5b (patch)
treefd621c6f3b11270d9bd670f4b129534909b5c456
parentf663762bf0aa5089fee41d62a4e7528f436164d4 (diff)
downloadpatch-e0f707523cab26f74ec23f4a20a27add8702ed5b.tar.gz
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.
-rw-r--r--ChangeLog7
-rw-r--r--src/pch.c10
-rw-r--r--tests/bad-filenames24
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 <meyering@redhat.com>
+ and Andreas Gruenbacher <agruen@linbit.com>
+
+ 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 <agruen@linbit.com>
* 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