Compare commits
10 Commits
ef1297429c
...
22f0ee4fb2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22f0ee4fb2 | ||
|
|
38260d0a17 | ||
|
|
3e9b07936f | ||
|
|
12ad752cdf | ||
|
|
e64632a2ad | ||
|
|
21ee4e312e | ||
|
|
2d8349f063 | ||
|
|
04bc1d6606 | ||
|
|
65993993a1 | ||
|
|
c91702b2ad |
61
backport-gzip-detect-invalid-input.patch
Normal file
61
backport-gzip-detect-invalid-input.patch
Normal file
@ -0,0 +1,61 @@
|
||||
From 63814d71ed81baec6f8b55513b561e045b160fa2 Mon Sep 17 00:00:00 2001
|
||||
From: Paul Eggert <eggert@trombone>
|
||||
Date: Tue, 28 Jun 2022 22:30:08 -0500
|
||||
Subject: [PATCH 1/2] gzip: detect invalid input
|
||||
|
||||
Conflict: Context adapt: Tracevv((stderr,"\\[%d,%d]", w-d, n));
|
||||
Reference: https://git.savannah.gnu.org/cgit/gzip.git/commit/?id=4b58eee79d3af3647adb4c78938d83970e788975
|
||||
|
||||
Problem reported by Young Mo Kang and fix from Mark Adler (Bug#56247).
|
||||
* inflate.c: Include stdbool.h.
|
||||
(fresh): New static var.
|
||||
* inflate.c (flush_output): Clear it.
|
||||
(inflate): Set it.
|
||||
(inflate_codes): Fail if the offset is outside a fresh input window.
|
||||
---
|
||||
inflate.c | 7 ++++++-
|
||||
1 file changed, 6 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/inflate.c b/inflate.c
|
||||
index f54eb65..d5b8c44 100644
|
||||
--- a/inflate.c
|
||||
+++ b/inflate.c
|
||||
@@ -117,6 +117,7 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
+#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "tailor.h"
|
||||
@@ -153,8 +154,9 @@ static int huft_free (struct huft *);
|
||||
"uch *slide;" and then malloc'ed in the latter case. The definition
|
||||
must be in unzip.h, included above. */
|
||||
/* unsigned wp; current position in slide */
|
||||
+static bool fresh;
|
||||
#define wp outcnt
|
||||
-#define flush_output(w) (wp=(w),flush_window())
|
||||
+#define flush_output(w) (fresh = false, wp = (w), flush_window ())
|
||||
|
||||
/* Tables for deflate from PKZIP's appnote.txt. */
|
||||
static unsigned border[] = { /* Order of the bit length code lengths */
|
||||
@@ -572,6 +574,8 @@ inflate_codes(struct huft *tl, struct huft *td, int bl, int bd)
|
||||
NEEDBITS(e)
|
||||
d = w - t->v.n - ((unsigned)b & mask_bits[e]);
|
||||
DUMPBITS(e)
|
||||
+ if (fresh && w <= d)
|
||||
+ return 1;
|
||||
Tracevv((stderr,"\\[%d,%d]", w-d, n));
|
||||
|
||||
/* do the copy */
|
||||
@@ -954,6 +958,7 @@ inflate(void)
|
||||
wp = 0;
|
||||
bk = 0;
|
||||
bb = 0;
|
||||
+ fresh = true;
|
||||
|
||||
|
||||
/* decompress until the last block */
|
||||
--
|
||||
2.27.0
|
||||
|
||||
29
backport-gzip-test-invalid-input-bug.patch
Normal file
29
backport-gzip-test-invalid-input-bug.patch
Normal file
@ -0,0 +1,29 @@
|
||||
From 7af8e5b0c722c9752940d5af3d8e387e90c227ce Mon Sep 17 00:00:00 2001
|
||||
From: Paul Eggert <eggert@trombone>
|
||||
Date: Tue, 28 Jun 2022 22:32:09 -0500
|
||||
Subject: [PATCH 2/2] gzip: test invalid-input bug
|
||||
|
||||
Conflict: Do not include NEWS change
|
||||
Reference: https://git.savannah.gnu.org/cgit/gzip.git/commit/?id=3e32e3c3583e5249394d45f7a1f9bf3156c8d32f
|
||||
|
||||
* NEWS: Mention the bug.
|
||||
* tests/unpack-invalid: Test for the bug.
|
||||
---
|
||||
tests/unpack-invalid | 1 +
|
||||
1 file changed, 1 insertion(+)
|
||||
|
||||
diff --git a/tests/unpack-invalid b/tests/unpack-invalid
|
||||
index 14984a1..f659aa8 100755
|
||||
--- a/tests/unpack-invalid
|
||||
+++ b/tests/unpack-invalid
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
fail=0
|
||||
for input in \
|
||||
+ '\37\213\b\0\0\0\0\0\0\3s\212\31204t\214T\v\216\274)q)\210\201A\341\377\377\37\f\23\30B\4\30\30\27+\\aih`hpd8\300\252\320\300\310\300\340\300\300\330\340\350\300\261\200!$\331M\201!\205q\341\253\214o+LM\331W\2300\310-|\305\300\256r\341\213\377\357\312\266$N\16E6\206\24\206\365\346\22\253\332L3l\366\334]]\244\275lM\355I\241;\377\343x\23\26M9\330\252\375\261\\%%\270\225\223wb\257\252\2\302\5\336\377\205\302\30\30\30\243$\03700010214\b0\260002p.`0dv\270 5o\371+7\237\366%%WL\246YMZ\234\367FN\277{\247\322\34\r\17\325\377\235\332\20\177\0\0@\23a\3\315\0\0\0' \
|
||||
'\037\036\000\000\037\213\010\000\000\000\000\000\002\003\036\000\000\000\002\003\037\213\010\000\000\000\000\000\002\003\355\301\001\015\000\000\000\302\240\037\000\302\240\037\213\010\000\000\000\000\000\002\003\355\301' \
|
||||
'\037\213\010\000\000\000\000\000\002\003\355\301\001\015\000\000\000\302\240\076\366\017\370\036\016\030\000\000\000\000\000\000\000\000\000\034\010\105\140\104\025\020\047\000\000\037\036\016\030\000\000\000'; do
|
||||
|
||||
--
|
||||
2.27.0
|
||||
|
||||
9
colorzgrep.csh
Normal file
9
colorzgrep.csh
Normal file
@ -0,0 +1,9 @@
|
||||
test -f /usr/libexec/grepconf.sh
|
||||
if ( $status == 1 ) exit
|
||||
|
||||
/usr/libexec/grepconf.sh -c
|
||||
if ( $status == 1 ) exit
|
||||
|
||||
alias zgrep 'zgrep --color=auto'
|
||||
alias zfgrep 'zfgrep --color=auto'
|
||||
alias zegrep 'zegrep --color=auto'
|
||||
6
colorzgrep.sh
Normal file
6
colorzgrep.sh
Normal file
@ -0,0 +1,6 @@
|
||||
[ -f /usr/libexec/grepconf.sh ] || return
|
||||
|
||||
/usr/libexec/grepconf.sh -c || return
|
||||
alias zgrep='zgrep --color=auto' 2>/dev/null
|
||||
alias zfgrep='zfgrep --color=auto' 2>/dev/null
|
||||
alias zegrep='zegrep --color=auto' 2>/dev/null
|
||||
244
fix-exit-status-on-broken-pipe.patch
Normal file
244
fix-exit-status-on-broken-pipe.patch
Normal file
@ -0,0 +1,244 @@
|
||||
From 75dac03adcdf79b8d38a87bf29f50bcde9fa46a5 Mon Sep 17 00:00:00 2001
|
||||
From: Paul Eggert <eggert@cs.ucla.edu>
|
||||
Date: Fri, 3 Feb 2023 01:19:44 -0800
|
||||
Subject: [PATCH] gzip: fix exit status on broken pipe
|
||||
|
||||
Fix gzip to behave like cat etc. when outputting to a broken pipe:
|
||||
i.e., exit with nonzero status if SIGPIPE is ignored, and be
|
||||
terminated by SIGPIPE otherwise.
|
||||
* NEWS: Mention this.
|
||||
* gzip.c: Do not install signal handlers unless creating an output
|
||||
file, for which signal handlers are needed. This avoids gzip
|
||||
having to deal with signal handlers when outputting to stdout.
|
||||
(exiting_signal): Remove. All uses removed.
|
||||
(main): Do not install signal handlers at first.
|
||||
(create_outfile): Instead, install them only when needed.
|
||||
(finish_up_gzip): New function, which generalizes abort_gzip.
|
||||
(abort_gzip): Use it.
|
||||
* tests/pipe-output: New test.
|
||||
* tests/Makefile.am (TESTS): Add it.
|
||||
* util.c (EPIPE): Default to 0.
|
||||
(write_error): Just warn if it is a pipe error, and suppress that
|
||||
warning if quiet. In any event exit with status 2 (warning),
|
||||
not status 1 (error).
|
||||
* zgrep.in: Treat gzip status 141 like status 2;
|
||||
it is a broken pipe either way.
|
||||
|
||||
Conflict: write_error() in util.c and NEWS file
|
||||
Reference: https://git.savannah.gnu.org/cgit/gzip.git/commit/?id=75dac03adcdf79b8d38a87bf29f50bcde9fa46a5
|
||||
|
||||
---
|
||||
gzip.c | 30 +++++++++++++++---------------
|
||||
gzip.h | 1 +
|
||||
tests/Makefile.am | 1 +
|
||||
tests/pipe-output | 46 ++++++++++++++++++++++++++++++++++++++++++++++
|
||||
util.c | 8 +++++++-
|
||||
zgrep.in | 4 ++--
|
||||
6 files changed, 72 insertions(+), 18 deletions(-)
|
||||
create mode 100755 tests/pipe-output
|
||||
|
||||
diff --git a/gzip.c b/gzip.c
|
||||
index 7547e19..7865a65 100644
|
||||
--- a/gzip.c
|
||||
+++ b/gzip.c
|
||||
@@ -202,11 +202,6 @@ struct timespec time_stamp;
|
||||
/* The set of signals that are caught. */
|
||||
static sigset_t caught_signals;
|
||||
|
||||
-/* If nonzero then exit with status WARNING, rather than with the usual
|
||||
- signal status, on receipt of a signal with this value. This
|
||||
- suppresses a "Broken Pipe" message with some shells. */
|
||||
-static int volatile exiting_signal;
|
||||
-
|
||||
/* If nonnegative, close this file descriptor and unlink remove_ofname
|
||||
on error. */
|
||||
static int volatile remove_ofname_fd = -1;
|
||||
@@ -647,11 +642,6 @@ int main (int argc, char **argv)
|
||||
ALLOC(ush, tab_prefix1, 1L<<(BITS-1));
|
||||
#endif
|
||||
|
||||
-#if SIGPIPE
|
||||
- exiting_signal = quiet ? SIGPIPE : 0;
|
||||
-#endif
|
||||
- install_signal_handlers ();
|
||||
-
|
||||
/* And get to work */
|
||||
if (file_count != 0) {
|
||||
if (to_stdout && !test && (!decompress || !ascii)) {
|
||||
@@ -1088,6 +1078,7 @@ volatile_strcpy (char volatile *dst, char const volatile *src)
|
||||
*/
|
||||
local int create_outfile()
|
||||
{
|
||||
+ static bool signal_handlers_installed;
|
||||
int name_shortened = 0;
|
||||
int flags = (O_WRONLY | O_CREAT | O_EXCL
|
||||
| (ascii && decompress ? 0 : O_BINARY));
|
||||
@@ -1105,6 +1096,12 @@ create_outfile ()
|
||||
}
|
||||
}
|
||||
|
||||
+ if (!signal_handlers_installed)
|
||||
+ {
|
||||
+ signal_handlers_installed = true;
|
||||
+ install_signal_handlers ();
|
||||
+ }
|
||||
+
|
||||
for (;;)
|
||||
{
|
||||
int open_errno;
|
||||
@@ -2103,12 +2100,17 @@ remove_output_file (bool signals_already_blocked)
|
||||
* Error handler.
|
||||
*/
|
||||
void
|
||||
+finish_up_gzip (int exitcode)
|
||||
+{
|
||||
+ if (0 <= remove_ofname_fd)
|
||||
+ remove_output_file (false);
|
||||
+ do_exit (exitcode);
|
||||
+}
|
||||
+void
|
||||
abort_gzip (void)
|
||||
{
|
||||
- remove_output_file (false);
|
||||
- do_exit(ERROR);
|
||||
+ finish_up_gzip (ERROR);
|
||||
}
|
||||
-
|
||||
/* ========================================================================
|
||||
* Signal handler.
|
||||
*/
|
||||
@@ -2116,8 +2118,6 @@ static void
|
||||
abort_gzip_signal (int sig)
|
||||
{
|
||||
remove_output_file (true);
|
||||
- if (sig == exiting_signal)
|
||||
- _exit (WARNING);
|
||||
signal (sig, SIG_DFL);
|
||||
raise (sig);
|
||||
}
|
||||
diff --git a/gzip.h b/gzip.h
|
||||
index fad2b3f..b26bc4f 100644
|
||||
--- a/gzip.h
|
||||
+++ b/gzip.h
|
||||
@@ -277,6 +277,7 @@ extern int unpack (int in, int out);
|
||||
extern int unlzh (int in, int out);
|
||||
|
||||
/* in gzip.c */
|
||||
+extern noreturn void finish_up_gzip (int);
|
||||
extern noreturn void abort_gzip (void);
|
||||
|
||||
/* in deflate.c */
|
||||
diff --git a/tests/Makefile.am b/tests/Makefile.am
|
||||
index 077b25c..80249b1 100644
|
||||
--- a/tests/Makefile.am
|
||||
+++ b/tests/Makefile.am
|
||||
@@ -25,6 +25,7 @@ TESTS = \
|
||||
memcpy-abuse \
|
||||
mixed \
|
||||
null-suffix-clobber \
|
||||
+ pipe-output \
|
||||
reproducible \
|
||||
stdin \
|
||||
timestamp \
|
||||
diff --git a/tests/pipe-output b/tests/pipe-output
|
||||
new file mode 100755
|
||||
index 0000000..5419963
|
||||
--- /dev/null
|
||||
+++ b/tests/pipe-output
|
||||
@@ -0,0 +1,46 @@
|
||||
+#!/bin/sh
|
||||
+# Check behavior of output to pipes
|
||||
+
|
||||
+# Copyright 2023 Free Software Foundation, Inc.
|
||||
+
|
||||
+# This program is free software: you can redistribute it and/or modify
|
||||
+# it under the terms of the GNU General Public License as published by
|
||||
+# the Free Software Foundation, either version 3 of the License, or
|
||||
+# (at your option) any later version.
|
||||
+
|
||||
+# This program is distributed in the hope that it will be useful,
|
||||
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
+# GNU General Public License for more details.
|
||||
+
|
||||
+# You should have received a copy of the GNU General Public License
|
||||
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
+# limit so don't run it by default.
|
||||
+
|
||||
+. "${srcdir=.}/init.sh"; path_prepend_ ..
|
||||
+
|
||||
+sleep 0.01 && sleep_amount=0.01 || sleep_amount=1
|
||||
+
|
||||
+echo a >a && echo b >b || framework_failure_
|
||||
+gzip a && gzip b || fail=1
|
||||
+
|
||||
+# Check that gzip etc. behave like cat if the output is a broken pipe.
|
||||
+for trap_pipe in trap :; do
|
||||
+ cat_status=$( (($trap_pipe '' PIPE
|
||||
+ sleep $sleep_amount
|
||||
+ cat <a.gz
|
||||
+ echo $? >&3) | : ) 3>&1)
|
||||
+ test 1 -lt $cat_status && test $cat_status -lt 128 && cat_status=1
|
||||
+
|
||||
+ for cmd in 'gunzip' 'gunzip -q' 'gzip -d' 'gzip -dq' \
|
||||
+ 'zcat' 'zcmp - b.gz' 'zdiff - b.gz' 'zgrep a'; do
|
||||
+ cmd_status=$( (($trap_pipe '' PIPE
|
||||
+ sleep $sleep_amount
|
||||
+ $cmd <a.gz
|
||||
+ echo $? >&3) | : ) 3>&1)
|
||||
+ test 1 -lt $cmd_status && test $cmd_status -lt 128 && cmd_status=1
|
||||
+ test $cat_status -eq $cmd_status || fail=1
|
||||
+ done
|
||||
+done
|
||||
+
|
||||
+Exit $fail
|
||||
diff --git a/util.c b/util.c
|
||||
index 642e620..71a937f 100644
|
||||
--- a/util.c
|
||||
+++ b/util.c
|
||||
@@ -36,6 +36,10 @@
|
||||
# define CHAR_BIT 8
|
||||
#endif
|
||||
|
||||
+#ifndef EPIPE
|
||||
+# define EPIPE 0
|
||||
+#endif
|
||||
+
|
||||
static int write_buffer (int, voidp, unsigned int);
|
||||
|
||||
/* ========================================================================
|
||||
@@ -500,11 +504,10 @@ void read_error()
|
||||
|
||||
void write_error()
|
||||
{
|
||||
- int e = errno;
|
||||
- fprintf (stderr, "\n%s: ", program_name);
|
||||
- errno = e;
|
||||
- perror(ofname);
|
||||
- abort_gzip();
|
||||
+ int exitcode = errno == EPIPE ? WARNING : ERROR;
|
||||
+ if (! (exitcode == WARNING && quiet))
|
||||
+ fprintf (stderr, "\n%s: %s: %s\n", program_name, ofname, strerror (errno));
|
||||
+ finish_up_gzip (exitcode);
|
||||
}
|
||||
|
||||
/* ========================================================================
|
||||
diff --git a/zgrep.in b/zgrep.in
|
||||
index 7aeee6c..504cca1 100644
|
||||
--- a/zgrep.in
|
||||
+++ b/zgrep.in
|
||||
@@ -253,9 +253,9 @@ do
|
||||
)
|
||||
r=$?
|
||||
|
||||
- # Ignore gzip status 2, as it is just a warning.
|
||||
+ # Ignore gzip status 2 or 141, as it is just a warning or broken pipe.
|
||||
# gzip status 1 is an error, like grep status 2.
|
||||
- test $gzip_status -eq 2 && gzip_status=0
|
||||
+ { test $gzip_status -eq 2 || test $gzip_status -eq 141; } && gzip_status=0
|
||||
test $gzip_status -eq 1 && gzip_status=2
|
||||
|
||||
# Use the more serious of the grep and gzip statuses.
|
||||
--
|
||||
2.33.0
|
||||
|
||||
27
gzip.spec
27
gzip.spec
@ -1,14 +1,20 @@
|
||||
Name: gzip
|
||||
Version: 1.12
|
||||
Release: 1
|
||||
Release: 5
|
||||
Summary: A data compression utility
|
||||
|
||||
License: GPLv3
|
||||
URL: https://www.gnu.org/software/gzip
|
||||
Source0: https://ftp.gnu.org/gnu/gzip/gzip-%{version}.tar.xz
|
||||
Source1: colorzgrep.csh
|
||||
Source2: colorzgrep.sh
|
||||
|
||||
Patch6000: backport-gzip-detect-invalid-input.patch
|
||||
Patch6001: backport-gzip-test-invalid-input-bug.patch
|
||||
|
||||
Patch9000: fix-verbose-disable.patch
|
||||
Patch9001: performance-neoncrc32-and-prfm.patch
|
||||
Patch9002: fix-exit-status-on-broken-pipe.patch
|
||||
|
||||
BuildRequires: gcc texinfo less autoconf automake
|
||||
Requires: coreutils
|
||||
@ -42,6 +48,12 @@ rm -rf %RPM_BUILD_ROOT
|
||||
# ncompress provides uncompress, may cause conflict.
|
||||
rm -f %{buildroot}%{_bindir}/uncompress
|
||||
|
||||
# config color alias for z*grep
|
||||
%global profiledir %{_sysconfdir}/profile.d
|
||||
mkdir -p %{buildroot}%{profiledir}
|
||||
install -p -m 644 %{SOURCE1} %{buildroot}%{profiledir}
|
||||
install -p -m 644 %{SOURCE2} %{buildroot}%{profiledir}
|
||||
|
||||
%check
|
||||
make check
|
||||
|
||||
@ -50,6 +62,7 @@ make check
|
||||
%doc AUTHORS ChangeLog README
|
||||
%license COPYING
|
||||
%{_bindir}/*
|
||||
%{profiledir}/*
|
||||
%exclude %{_infodir}/dir
|
||||
|
||||
%files help
|
||||
@ -58,6 +71,18 @@ make check
|
||||
%{_mandir}/man1/*
|
||||
|
||||
%changelog
|
||||
* Wed Jul 10 2024 wangziliang <wangziliang@kylinos.cn> - 1.12-5
|
||||
- fix exit status on broken pipe
|
||||
|
||||
* Thu Jun 01 2023 renhognxun <renhongxun@h-partners.com> - 1.12-4
|
||||
- fix typo error in csh
|
||||
|
||||
* Tue Sep 20 2022 renhongxun <renhongxun@h-partners.com> - 1.12-3
|
||||
- config color alias for z*grep
|
||||
|
||||
* Thu Jul 28 2022 Lv Ying <lvying6@huawei.com> - 1.12-2
|
||||
- backport bugfix patch: detect invalid input
|
||||
|
||||
* Sat Jun 11 2022 YukariChiba <i@0x7f.cc> - 1.12-1
|
||||
- Upgrade version.
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user