<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "http://bugs.gentoo.org/bugzilla.dtd">

<bugzilla version="2.22.7"
          urlbase="http://bugs.gentoo.org/"
          maintainer="bugzilla@gentoo.org"
>

    <bug>
          <bug_id>90626</bug_id>
          
          <creation_ts>2005-04-27 08:28 0000</creation_ts>
          <short_desc>app-arch/gzip zgrep issue (CAN-2005-0758)</short_desc>
          <delta_ts>2005-05-09 12:44:59 0000</delta_ts>
          
          
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>Gentoo Security</product>
          <component>Vulnerabilities</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <status_whiteboard>A3 [glsa] jaervosz</status_whiteboard>
          
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>89946</dependson>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>jaervosz@gentoo.org</reporter>
          <assigned_to>security@gentoo.org</assigned_to>
          

      

      
          <long_desc isprivate="0">
            <who>jaervosz@gentoo.org</who>
            <bug_when>2005-04-27 08:28:31 0000</bug_when>
            <thetext>This old issue seems unfixed in our zgrep.

&gt; zgrep contains the following gem:
&gt;
&gt; for i do
&gt; [snip]
&gt;      if test $with_filename -eq 1; then
&gt;        sed_script=&quot;s|^[^:]*:|${i}:|&quot;
&gt;      else
&gt;        sed_script=&quot;s|^|${i}:|&quot;
&gt;      fi
&gt;      $grep $opt &quot;$pat&quot; | sed &quot;$sed_script&quot;
&gt; [snip]
&gt; done
&gt;
&gt; Aside of the correctness issues (try to use zgrep on files with e.g. &apos;&amp;&apos; in
&gt; names), it leads to obvious fun when zgrep arguments had been obtained
&gt; by globbing in an untrusted place.  Even with standard sed we have at
&gt; least ;w&lt;filename&gt;; to deal with; for GNU sed there&apos;s also ;e; on top
&gt; of that (execute the contents of pattern space).  bzgrep is no better -
&gt; it&apos;s based on zgrep.
&gt;
&gt; AFAICS, there are two solutions - one is to do what *BSD had done and
&gt; make grep(1) use zlib and libbz; then zgrep et.al. become links to
&gt; grep.  Another is to quote \, |, ; and newlines, which means extra
&gt; invocation of sed(1)...</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>jaervosz@gentoo.org</who>
            <bug_when>2005-04-27 08:42:07 0000</bug_when>
            <thetext>And the proposed patch by Red Hat:

--- zgrep.in
+++ zgrep.in
@@ -24,7 +24,7 @@
</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>jaervosz@gentoo.org</who>
            <bug_when>2005-04-27 08:42:07 0000</bug_when>
            <thetext>And the proposed patch by Red Hat:

--- zgrep.in
+++ zgrep.in
@@ -24,7 +24,7 @@
 
 PATH=&quot;BINDIR:$PATH&quot;; export PATH
 
-prog=`echo $0 | sed &apos;s|.*/||&apos;`
+prog=`echo &quot;$0&quot; | sed &apos;s|.*/||&apos;`
 case &quot;$prog&quot; in
        *egrep) grep=${EGREP-egrep -a}  ;;
        *fgrep) grep=${FGREP-fgrep -a}  ;;
@@ -112,12 +112,15 @@
   fi
   $uncompress -cdfq &quot;$i&quot; |
     if test $files_with_matches -eq 1; then
-      $grep $opt &quot;$pat&quot; &gt; /dev/null &amp;&amp; echo $i
+      $grep $opt &quot;$pat&quot; &gt; /dev/null &amp;&amp; printf &quot;%s\n&quot; &quot;$i&quot;
     elif test $files_without_matches -eq 1; then
-      $grep $opt &quot;$pat&quot; &gt; /dev/null || echo $i
+      $grep $opt &quot;$pat&quot; &gt; /dev/null || printf &quot;%s\n&quot; &quot;$i&quot;
     elif test $with_filename -eq 0 &amp;&amp; { test $# -eq 1 || test $no_filename -eq 1; }; then
       $grep $opt &quot;$pat&quot;
     else
+      i=${i//\\/\\\\}
+      i=${i//|/\\|}
+      i=${i//&amp;/\\&amp;}
       if test $with_filename -eq 1; then
        sed_script=&quot;s|^[^:]*:|${i}:|&quot;
       else</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>vapier@gentoo.org</who>
            <bug_when>2005-05-02 15:01:10 0000</bug_when>
            <thetext>gzip-1.3.5-r6 now in portage with the fix

also we can probably open the bug considering redhat has the fix in their public cvs</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>jaervosz@gentoo.org</who>
            <bug_when>2005-05-02 22:23:23 0000</bug_when>
            <thetext>Opening.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>jaervosz@gentoo.org</who>
            <bug_when>2005-05-09 12:44:59 0000</bug_when>
            <thetext>GLSA 200505-05</thetext>
          </long_desc>
      
    </bug>

</bugzilla>