From: Paul Eggert Date: Sun, 26 Nov 2006 20:48:29 +0000 (+0000) Subject: * zgrep.in: If the file name contains newline, &, \, or |, escape X-Git-Tag: v1.3.12~55 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=a7528501d19c16640044bc0ff86a6eab8d4d637b;p=debian%2Fgzip * zgrep.in: If the file name contains newline, &, \, or |, escape the character so that 'sed' doesn't mishandle it as a replacement. Problem reported by Bdale Garbee. --- diff --git a/ChangeLog b/ChangeLog index c4fb67c..78d6ebb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-11-26 Paul Eggert + + * zgrep.in: If the file name contains newline, &, \, or |, escape + the character so that 'sed' doesn't mishandle it as a replacement. + Problem reported by Bdale Garbee. + 2006-11-25 Paul Eggert * gzip.1 (OPTIONS): ouput -> output. Problem reported by Matt diff --git a/zgrep.in b/zgrep.in index 0172883..e309f05 100644 --- a/zgrep.in +++ b/zgrep.in @@ -116,10 +116,27 @@ for i do elif test $with_filename -eq 0 && { test $# -eq 1 || test $no_filename -eq 1; }; then $grep $opt "$pat" else + escaped= + while :; do + case $i in + *' +'*) + char=' +' repl='\\n';; + *'&'*) char='&' repl='\&';; + *'\'*) char='\\' repl='\\';; + *'|'*) char='|' repl='\|';; + *) break;; + esac + up_to_first_char="\\([^$char]*\\)" + after_first_char="[^$char]*$char\\(.*\\)" + escaped=$escaped`expr "X$i" : "X$up_to_first_char"`$repl + i=`expr "X$i" : "$after_first_char"` + done if test $with_filename -eq 1; then - sed_script="s|^[^:]*:|${i}:|" + sed_script="s|[^:]*|$escaped$i|" else - sed_script="s|^|${i}:|" + sed_script="s|^|$escaped$i:|" fi # Fail if either grep or sed fails.