Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/compress uncompress: if the source is broken, don't ...



details:   https://anonhg.NetBSD.org/src/rev/32e246748b32
branches:  trunk
changeset: 366361:32e246748b32
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun May 22 21:39:44 2022 +0000

description:
uncompress: if the source is broken, don't delete the target

Fixes the second half of PR bin/19722, reported by Giorgos Keramidas.

diffstat:

 tests/usr.bin/compress/t_pr_19722.sh |   9 ++++++---
 usr.bin/compress/compress.c          |  21 +++++++++++++++------
 2 files changed, 21 insertions(+), 9 deletions(-)

diffs (79 lines):

diff -r 23635cc9f666 -r 32e246748b32 tests/usr.bin/compress/t_pr_19722.sh
--- a/tests/usr.bin/compress/t_pr_19722.sh      Sun May 22 21:31:48 2022 +0000
+++ b/tests/usr.bin/compress/t_pr_19722.sh      Sun May 22 21:39:44 2022 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: t_pr_19722.sh,v 1.3 2022/05/22 21:16:50 rillig Exp $
+#      $NetBSD: t_pr_19722.sh,v 1.4 2022/05/22 21:39:44 rillig Exp $
 #
 # Copyright (c) 2022 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -148,6 +148,10 @@
 uncompress_broken_source_existing_target_body()
 {
        # PR 19722: uncompressing a broken source removes existing target
+       #
+       # Before compress.c 1.29 from 2022-05-22, uncompress removed an
+       # existing target before checking that the source has the correct
+       # format.
 
        echo 'broken' > file.Z
        echo 'before' > file
@@ -158,8 +162,7 @@
            uncompress -f file.Z
 
        atf_check -o 'inline:broken\n' cat file.Z
-       # FIXME: Must not be modified.
-       atf_check test ! -f file
+       atf_check -o 'inline:before\n' cat file
 }
 
 
diff -r 23635cc9f666 -r 32e246748b32 usr.bin/compress/compress.c
--- a/usr.bin/compress/compress.c       Sun May 22 21:31:48 2022 +0000
+++ b/usr.bin/compress/compress.c       Sun May 22 21:39:44 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compress.c,v 1.28 2022/05/22 21:16:50 rillig Exp $     */
+/*     $NetBSD: compress.c,v 1.29 2022/05/22 21:39:44 rillig Exp $     */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)compress.c 8.2 (Berkeley) 1/7/94";
 #else
-__RCSID("$NetBSD: compress.c,v 1.28 2022/05/22 21:16:50 rillig Exp $");
+__RCSID("$NetBSD: compress.c,v 1.29 2022/05/22 21:39:44 rillig Exp $");
 #endif
 #endif /* not lint */
 
@@ -318,10 +318,6 @@
                cwarn("%s", in);
                goto err;
        }
-       if ((ofp = fopen(out, "w")) == NULL) {
-               cwarn("%s", out);
-               goto err;
-       }
        if (!isstdin) {
                if (stat(in, &sb)) {
                        cwarn("%s", in);
@@ -333,6 +329,19 @@
                        isreg = 1;
        } else
                isreg = 0;
+       if ((nr = fread(buf, 1, sizeof(buf), ifp)) == 0) {
+               cwarn("%s", in);
+               goto err;
+       }
+
+       if ((ofp = fopen(out, "w")) == NULL) {
+               cwarn("%s", out);
+               goto err;
+       }
+       if (fwrite(buf, 1, nr, ofp) != nr) {
+               cwarn("%s", out);
+               goto err;
+       }
 
        oreg <<= 1;
        while ((nr = fread(buf, 1, sizeof(buf), ifp)) != 0)



Home | Main Index | Thread Index | Old Index