Module Name:    src
Committed By:   martin
Date:           Sun Feb  4 11:07:41 UTC 2024

Modified Files:
        src/usr.bin/gzip [netbsd-10]: gzip.1 gzip.c unlz.c unpack.c

Log Message:
Pull up the following, requested by mrg in ticket #582:

        usr.bin/gzip/gzip.1                             up to 1.32
        usr.bin/gzip/gzip.c                             up to 1.122
        usr.bin/gzip/unlz.c                             up to 1.8
        usr.bin/gzip/unpack.c                           up to 1.4

Sync usr.bin/gzip to HEAD to fix a few minor issues, including
PR 57858 and PR 57855.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.31.10.1 src/usr.bin/gzip/gzip.1
cvs rdiff -u -r1.118 -r1.118.2.1 src/usr.bin/gzip/gzip.c
cvs rdiff -u -r1.7 -r1.7.2.1 src/usr.bin/gzip/unlz.c
cvs rdiff -u -r1.3 -r1.3.14.1 src/usr.bin/gzip/unpack.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/gzip/gzip.1
diff -u src/usr.bin/gzip/gzip.1:1.31 src/usr.bin/gzip/gzip.1:1.31.10.1
--- src/usr.bin/gzip/gzip.1:1.31	Fri Oct 26 22:10:15 2018
+++ src/usr.bin/gzip/gzip.1	Sun Feb  4 11:07:40 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: gzip.1,v 1.31 2018/10/26 22:10:15 christos Exp $
+.\"	$NetBSD: gzip.1,v 1.31.10.1 2024/02/04 11:07:40 martin Exp $
 .\"
 .\" Copyright (c) 1997, 2003, 2004, 2008, 2009, 2015, 2017 Matthew R. Green
 .\" All rights reserved.
@@ -217,4 +217,4 @@ version 20170803.
 This implementation of
 .Nm
 was written by
-.An Matthew R. Green Aq Mt m...@eterna.com.au .
+.An Matthew R. Green Aq Mt m...@eterna23.net .

Index: src/usr.bin/gzip/gzip.c
diff -u src/usr.bin/gzip/gzip.c:1.118 src/usr.bin/gzip/gzip.c:1.118.2.1
--- src/usr.bin/gzip/gzip.c:1.118	Sat Jan 22 14:00:45 2022
+++ src/usr.bin/gzip/gzip.c	Sun Feb  4 11:07:40 2024
@@ -1,8 +1,7 @@
-/*	$NetBSD: gzip.c,v 1.118 2022/01/22 14:00:45 christos Exp $	*/
+/*	$NetBSD: gzip.c,v 1.118.2.1 2024/02/04 11:07:40 martin Exp $	*/
 
 /*
- * Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008, 2009, 2010, 2011, 2015, 2017
- *    Matthew R. Green
+ * Copyright (c) 1997-2024 Matthew R. Green
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,9 +28,9 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008,\
- 2009, 2010, 2011, 2015, 2017 Matthew R. Green.  All rights reserved.");
-__RCSID("$NetBSD: gzip.c,v 1.118 2022/01/22 14:00:45 christos Exp $");
+__COPYRIGHT("@(#) Copyright (c) 1997-2024 Matthew R. Green. "
+	    "All rights reserved.");
+__RCSID("$NetBSD: gzip.c,v 1.118.2.1 2024/02/04 11:07:40 martin Exp $");
 #endif /* not lint */
 
 /*
@@ -173,7 +172,7 @@ static suffixes_t suffixes[] = {
 #define NUM_SUFFIXES (sizeof suffixes / sizeof suffixes[0])
 #define SUFFIX_MAXLEN	30
 
-static	const char	gzip_version[] = "NetBSD gzip 20170803";
+static	const char	gzip_version[] = "NetBSD gzip 20240203";
 
 static	int	cflag;			/* stdout mode */
 static	int	dflag;			/* decompress mode */
@@ -1114,14 +1113,14 @@ copymodes(int fd, const struct stat *sbp
 	if (fchmod(fd, sb.st_mode) < 0)
 		maybe_warn("couldn't fchmod: %s", file);
 
-	/* only try flags if they exist already */
-        if (sb.st_flags != 0 && fchflags(fd, sb.st_flags) < 0)
-		maybe_warn("couldn't fchflags: %s", file);
-
 	TIMESPEC_TO_TIMEVAL(&times[0], &sb.st_atimespec);
 	TIMESPEC_TO_TIMEVAL(&times[1], &sb.st_mtimespec);
 	if (futimes(fd, times) < 0)
 		maybe_warn("couldn't utimes: %s", file);
+
+	/* finally, only try flags if they exist already */
+        if (sb.st_flags != 0 && fchflags(fd, sb.st_flags) < 0)
+		maybe_warn("couldn't fchflags: %s", file);
 }
 #endif
 
@@ -1400,7 +1399,7 @@ file_uncompress(char *file, char *outfil
 	struct stat isb, osb;
 	off_t size;
 	ssize_t rbytes;
-	unsigned char header1[4];
+	unsigned char fourbytes[4];
 	enum filetype method;
 	int fd, ofd, zfd = -1;
 	size_t in_size;
@@ -1434,8 +1433,8 @@ file_uncompress(char *file, char *outfil
 		goto lose;
 	}
 
-	rbytes = read(fd, header1, sizeof header1);
-	if (rbytes != sizeof header1) {
+	rbytes = read(fd, fourbytes, sizeof fourbytes);
+	if (rbytes != sizeof fourbytes) {
 		/* we don't want to fail here. */
 #ifndef SMALL
 		if (fflag)
@@ -1449,7 +1448,7 @@ file_uncompress(char *file, char *outfil
 	}
 	infile_newdata(rbytes);
 
-	method = file_gettype(header1);
+	method = file_gettype(fourbytes);
 #ifndef SMALL
 	if (fflag == 0 && method == FT_UNKNOWN) {
 		maybe_warnx("%s: not in gzip format", file);
@@ -1473,7 +1472,7 @@ file_uncompress(char *file, char *outfil
 		infile_newdata(rv);
 		timestamp = ts[3] << 24 | ts[2] << 16 | ts[1] << 8 | ts[0];
 
-		if (header1[3] & ORIG_NAME) {
+		if (fourbytes[3] & ORIG_NAME) {
 			rbytes = pread(fd, name, sizeof(name) - 1, GZIP_ORIGNAME);
 			if (rbytes < 0) {
 				maybe_warn("can't read %s", file);
@@ -1787,7 +1786,7 @@ static void
 handle_stdin(void)
 {
 	struct stat isb;
-	unsigned char header1[4];
+	unsigned char fourbytes[4];
 	size_t in_size;
 	off_t usize, gsize;
 	enum filetype method;
@@ -1818,16 +1817,16 @@ handle_stdin(void)
 		goto out;
 	}
 
-	bytes_read = read_retry(STDIN_FILENO, header1, sizeof header1);
+	bytes_read = read_retry(STDIN_FILENO, fourbytes, sizeof fourbytes);
 	if (bytes_read == -1) {
 		maybe_warn("can't read stdin");
 		goto out;
-	} else if (bytes_read != sizeof(header1)) {
+	} else if (bytes_read != sizeof(fourbytes)) {
 		maybe_warnx("(stdin): unexpected end of file");
 		goto out;
 	}
 
-	method = file_gettype(header1);
+	method = file_gettype(fourbytes);
 	switch (method) {
 	default:
 #ifndef SMALL
@@ -1835,17 +1834,17 @@ handle_stdin(void)
 			maybe_warnx("unknown compression format");
 			goto out;
 		}
-		usize = cat_fd(header1, sizeof header1, &gsize, STDIN_FILENO);
+		usize = cat_fd(fourbytes, sizeof fourbytes, &gsize, STDIN_FILENO);
 		break;
 #endif
 	case FT_GZIP:
 		usize = gz_uncompress(STDIN_FILENO, STDOUT_FILENO,
-			      (char *)header1, sizeof header1, &gsize, "(stdin)");
+			      (char *)fourbytes, sizeof fourbytes, &gsize, "(stdin)");
 		break;
 #ifndef NO_BZIP2_SUPPORT
 	case FT_BZIP2:
 		usize = unbzip2(STDIN_FILENO, STDOUT_FILENO,
-				(char *)header1, sizeof header1, &gsize);
+				(char *)fourbytes, sizeof fourbytes, &gsize);
 		break;
 #endif
 #ifndef NO_COMPRESS_SUPPORT
@@ -1855,27 +1854,27 @@ handle_stdin(void)
 			goto out;
 		}
 
-		usize = zuncompress(in, stdout, (char *)header1,
-		    sizeof header1, &gsize);
+		usize = zuncompress(in, stdout, (char *)fourbytes,
+		    sizeof fourbytes, &gsize);
 		fclose(in);
 		break;
 #endif
 #ifndef NO_PACK_SUPPORT
 	case FT_PACK:
 		usize = unpack(STDIN_FILENO, STDOUT_FILENO,
-			       (char *)header1, sizeof header1, &gsize);
+			       (char *)fourbytes, sizeof fourbytes, &gsize);
 		break;
 #endif
 #ifndef NO_XZ_SUPPORT
 	case FT_XZ:
 		usize = unxz(STDIN_FILENO, STDOUT_FILENO,
-			     (char *)header1, sizeof header1, &gsize);
+			     (char *)fourbytes, sizeof fourbytes, &gsize);
 		break;
 #endif
 #ifndef NO_LZ_SUPPORT
 	case FT_LZ:
 		usize = unlz(STDIN_FILENO, STDOUT_FILENO,
-			     (char *)header1, sizeof header1, &gsize);
+			     (char *)fourbytes, sizeof fourbytes, &gsize);
 		break;
 #endif
 	}
@@ -2037,7 +2036,7 @@ handle_dir(char *dir)
 
 	path_argv[0] = dir;
 	path_argv[1] = 0;
-	fts = fts_open(path_argv, FTS_PHYSICAL, NULL);
+	fts = fts_open(path_argv, FTS_PHYSICAL | FTS_NOCHDIR, NULL);
 	if (fts == NULL) {
 		warn("couldn't fts_open %s", dir);
 		return;
@@ -2055,7 +2054,7 @@ handle_dir(char *dir)
 			maybe_warn("%s", entry->fts_path);
 			continue;
 		case FTS_F:
-			handle_file(entry->fts_name, entry->fts_statp);
+			handle_file(entry->fts_path, entry->fts_statp);
 		}
 	}
 	(void)fts_close(fts);

Index: src/usr.bin/gzip/unlz.c
diff -u src/usr.bin/gzip/unlz.c:1.7 src/usr.bin/gzip/unlz.c:1.7.2.1
--- src/usr.bin/gzip/unlz.c:1.7	Fri Sep 10 21:52:17 2021
+++ src/usr.bin/gzip/unlz.c	Sun Feb  4 11:07:40 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: unlz.c,v 1.7 2021/09/10 21:52:17 rillig Exp $	*/
+/*	$NetBSD: unlz.c,v 1.7.2.1 2024/02/04 11:07:40 martin Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -616,8 +616,6 @@ unlz(int fin, int fout, char *pre, size_
 
 	char header[HDR_SIZE];
 
-	if (prelen > sizeof(header))
-		return -1;
 	if (pre && prelen)
 		memcpy(header, pre, prelen);
 	

Index: src/usr.bin/gzip/unpack.c
diff -u src/usr.bin/gzip/unpack.c:1.3 src/usr.bin/gzip/unpack.c:1.3.14.1
--- src/usr.bin/gzip/unpack.c:1.3	Fri Aug  4 07:27:08 2017
+++ src/usr.bin/gzip/unpack.c	Sun Feb  4 11:07:40 2024
@@ -1,5 +1,5 @@
 /*	$FreeBSD: head/usr.bin/gzip/unpack.c 194579 2009-06-21 09:39:43Z delphij $	*/
-/*	$NetBSD: unpack.c,v 1.3 2017/08/04 07:27:08 mrg Exp $	*/
+/*	$NetBSD: unpack.c,v 1.3.14.1 2024/02/04 11:07:40 martin Exp $	*/
 
 /*-
  * Copyright (c) 2009 Xin LI <delp...@freebsd.org>
@@ -153,9 +153,6 @@ unpack_parse_header(int in, int out, cha
 	ssize_t bytesread;		/* Bytes read from the file */
 	int i, j, thisbyte;
 
-	if (prelen > sizeof hdr)
-		maybe_err("prelen too long");
-
 	/* Prepend the header buffer if we already read some data */
 	if (prelen != 0)
 		memcpy(hdr, pre, prelen);

Reply via email to