On 08/23/2012 10:31 AM, Ondrej Oprala wrote:
> On 08/23/2012 11:16 AM, Pádraig Brady wrote:
>> On 08/23/2012 10:06 AM, Ondrej Oprala wrote:
>>> echo -E "$ex_output" > exp
>> That's using the shell's version which may not be portable.
>> To select the built echo binary use: env echo ...
>> Or even better, use: printf

> Corrected :)

Cool.
I've adjusted docs/tests/filename_unescape()
in the attached diff, which I'll push in a little while.

Note the filename_unescape() adjustment is to
ensure that '\0' is not written outside the
passed in buffer limits. This eases ongoing maintenance,
but is currently inconsequential as in the BSD case
we will write '\0' to the same place just after,
while in the standard case with the file name at
the end of the line, '\0' will already be present.

thanks!
Pádraig.
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 0710fce..88d3956 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -3708,12 +3708,13 @@ indicating there was a failure.
 @item --tag
 @opindex --tag
 @cindex BSD output
-Create a BSD style output. If the file name contains a '\' or a newline,
-put a '\' at the beginning of the corresponding line. Filenames containing
-these characters will also be escaped just as they would be without
-@option{--tag}. The @option{--tag} option implies binary mode. If both
-@option{--tag} and @option{--text} are specified, issue a warning and
-exit nonzero.
+Output BSD style checksums, which indicate the checksum algorithm used.
+As a @acronym{GNU} extension, file names with problematic characters
+are escaped as described above, with the same escaping indicator of @samp{\}
+at the start of the line, being used.
+The @option{--tag} option implies binary mode, and is disallowed with
+@option{--text} mode as supporting that would unnecessarily complicate
+the output format, while providing little benefit.
 
 @item -t
 @itemx --text
diff --git a/src/md5sum.c b/src/md5sum.c
index 85c96b5..ea76c52 100644
--- a/src/md5sum.c
+++ b/src/md5sum.c
@@ -267,7 +267,8 @@ filename_unescape (char *s, size_t s_len)
           break;
         }
     }
-  *dst = '\0';
+  if (dst < s + s_len)
+    *dst = '\0';
 
   return s;
 }
diff --git a/tests/misc/md5sum-bsd b/tests/misc/md5sum-bsd
index 14abc07..2970484 100755
--- a/tests/misc/md5sum-bsd
+++ b/tests/misc/md5sum-bsd
@@ -1,5 +1,6 @@
 #!/bin/sh
-# make sure 'md5sum -c' works for alternate BSD format (md5 -r)
+# 'md5sum' tests for generation and checking of
+# BSD traditional and alternate formats (md5 [-r])
 
 # Copyright (C) 2011-2012 Free Software Foundation, Inc.
 
@@ -19,6 +20,9 @@
 . "${srcdir=.}/init.sh"; path_prepend_ ../src
 print_ver_ md5sum
 
+## BSD alternate format tests ##
+
+# Ensure we can --check BSD alternate format.
 # Note we start this list with a name
 # that's unambiguous in BSD format.
 # I.E. one not starting with ' ' or '*'
@@ -38,37 +42,44 @@ md5sum --strict -c check.md5 || fail=1
 # an option to avoid the ambiguity.
 tail -n+2 check.md5 | md5sum --strict -c && fail=1
 
-#--tag option test
 
+## BSD traditional format tests (--tag option) ##
+
+# Ensure --tag and --text are mutually exclusive
+# We don't support --text with BSD tradition format,
+# as that would complicate the output format,
+# while providing little benefit over --text processing
+# available with the default md5sum output format.
+md5sum --tag --text /dev/null && fail=1
+
+# Ensure we can --check BSD traditional format we produce
+rm check.md5
 for i in 'a' ' b' '*c' 'dd' ' '; do
   echo "$i" > "$i"
-  md5sum --tag "$i" >> check.md5sum
+  md5sum --tag "$i" >> check.md5
 done
-sed 's/  / /' check.md5sum > check.md5
-
-md5sum --strict -c check.md5sum || fail=1
 md5sum --strict -c check.md5 || fail=1
 
-#--tag testing filenames with \t \n and trailing \
-
+# Ensure we can --check BSD traditional format we produce
+# with the GNU extension of escaped newlines
 nl='
 '
 tab='  '
+rm check.md5
 for i in 'a\b' 'a\' "a${nl}b" "a${tab}b"; do
   :> "$i"
-  md5sum --tag "$i" >> check.md5sum
+  md5sum --tag "$i" >> check.md5
 done
+md5sum --strict -c check.md5 || fail=1
 
-md5sum --strict -c check.md5sum || fail=1
-
+# Ensure BSD traditional format with GNU extension escapes
+# is in the expected format
 ex_file='test
 \\file'
 ex_output='\MD5 (test\n\\\\file) = d41d8cd98f00b204e9800998ecf8427e'
-
 touch "$ex_file"
 printf "%s\n" "$ex_output" > exp
 md5sum --tag "$ex_file" > out
-
 compare exp out || fail=1
 
 Exit $fail

Reply via email to