37a940
From d74a30d45c6834c8e9f87115197370fe86656d81 Mon Sep 17 00:00:00 2001
37a940
From: Jim Meyering <meyering@fb.com>
37a940
Date: Mon, 4 Apr 2022 23:52:49 -0700
37a940
Subject: zgrep: add NEWS and tests for this exploitable bug
37a940
37a940
* tests/zgrep-abuse: New file, based on PoC by cleemy desu wayo.
37a940
* tests/Makefile.am (TESTS): Add it.
37a940
* NEWS: Mention the exploit.
37a940
The bug appears to have been present since the beginning.
37a940
---
37a940
 tests/Makefile.am |  1 +
37a940
 tests/zgrep-abuse | 41 +++++++++++++++++++++++++++++++++++++++++
37a940
 3 files changed, 45 insertions(+)
37a940
 create mode 100755 tests/zgrep-abuse
37a940
37a940
diff --git a/tests/Makefile.am b/tests/Makefile.am
37a940
index d09672e..5f148d6 100644
37a940
--- a/tests/Makefile.am
37a940
+++ b/tests/Makefile.am
37a940
@@ -36,6 +36,7 @@ TESTS =					\
37a940
   z-suffix				\
37a940
   zdiff					\
37a940
   zgrep-f				\
37a940
+  zgrep-abuse				\
37a940
   zgrep-context				\
37a940
   zgrep-signal				\
37a940
   znew-k
37a940
diff --git a/tests/zgrep-abuse b/tests/zgrep-abuse
37a940
new file mode 100755
37a940
index 0000000..3e8a8f9
37a940
--- /dev/null
37a940
+++ b/tests/zgrep-abuse
37a940
@@ -0,0 +1,41 @@
37a940
+#!/bin/sh
37a940
+# Show how zgrep applied to a crafted file name may overwrite
37a940
+# a selected file with chosen content.  Fixed in gzip-1.12.
37a940
+
37a940
+# Copyright (C) 2022 Free Software Foundation, Inc.
37a940
+
37a940
+# This program is free software: you can redistribute it and/or modify
37a940
+# it under the terms of the GNU General Public License as published by
37a940
+# the Free Software Foundation, either version 3 of the License, or
37a940
+# (at your option) any later version.
37a940
+
37a940
+# This program is distributed in the hope that it will be useful,
37a940
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
37a940
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37a940
+# GNU General Public License for more details.
37a940
+
37a940
+# You should have received a copy of the GNU General Public License
37a940
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
37a940
+# limit so don't run it by default.
37a940
+
37a940
+. "${srcdir=.}/init.sh"; path_prepend_ ..
37a940
+
37a940
+: > z || framework_failure_
37a940
+echo test |gzip > 'z|
37a940
+p
37a940
+1s|.*|chosen-content|
37a940
+1w hacked
37a940
+etouch .\x2fhacked2
37a940
+d
37a940
+#
37a940
+#' || framework_failure_
37a940
+
37a940
+fail=0
37a940
+
37a940
+zgrep test z* > /dev/null
37a940
+
37a940
+# Before the fix, each of these would be created.
37a940
+test -f hacked && fail=1
37a940
+test -f hacked2 && fail=1
37a940
+
37a940
+Exit $fail
37a940
-- 
37a940
cgit v1.1
37a940