64c81e5
From dc9740df61e575e8c3148b7bd3c147a81ea00c7c Mon Sep 17 00:00:00 2001
64c81e5
From: Lasse Collin <lasse.collin@tukaani.org>
64c81e5
Date: Mon, 4 Apr 2022 23:52:49 -0700
64c81e5
Subject: zgrep: avoid exploit via multi-newline file names
64c81e5
64c81e5
* zgrep.in: The issue with the old code is that with multiple
64c81e5
newlines, the N-command will read the second line of input,
64c81e5
then the s-commands will be skipped because it's not the end
64c81e5
of the file yet, then a new sed cycle starts and the pattern
64c81e5
space is printed and emptied. So only the last line or two get
64c81e5
escaped. This patch makes sed read all lines into the pattern
64c81e5
space and then do the escaping.
64c81e5
64c81e5
This vulnerability was discovered by:
64c81e5
cleemy desu wayo working with Trend Micro Zero Day Initiative
64c81e5
---
64c81e5
 zgrep.in | 10 +++++++---
64c81e5
 1 file changed, 7 insertions(+), 3 deletions(-)
64c81e5
64c81e5
diff --git a/zgrep.in b/zgrep.in
64c81e5
index 345dae3..bdf7da2 100644
64c81e5
--- a/zgrep.in
64c81e5
+++ b/zgrep.in
64c81e5
@@ -222,9 +222,13 @@ do
64c81e5
 '* | *'&'* | *'\'* | *'|'*)
64c81e5
         i=$(printf '%s\n' "$i" |
64c81e5
             sed '
64c81e5
-              $!N
64c81e5
-              $s/[&\|]/\\&/g
64c81e5
-              $s/\n/\\n/g
64c81e5
+              :start
64c81e5
+              $!{
64c81e5
+                N
64c81e5
+                b start
64c81e5
+              }
64c81e5
+              s/[&\|]/\\&/g
64c81e5
+              s/\n/\\n/g
64c81e5
             ');;
64c81e5
       esac
64c81e5
       sed_script="s|^|$i:|"
64c81e5
-- 
64c81e5
cgit v1.1
64c81e5