Module Name: src
Committed By: christos
Date: Thu Dec 5 17:17:43 UTC 2024
Modified Files:
src/usr.sbin/mtree: compare.c crc.c create.c extern.h misc.c spec.c
verify.c
Log Message:
PR/58875: Jose Luis Duran: Produce consistent checksums in verification
by scanning directories in the same order as usual. While here, fix some
incorrect types.
To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/usr.sbin/mtree/compare.c
cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/mtree/crc.c
cvs rdiff -u -r1.78 -r1.79 src/usr.sbin/mtree/create.c
cvs rdiff -u -r1.40 -r1.41 src/usr.sbin/mtree/extern.h
cvs rdiff -u -r1.34 -r1.35 src/usr.sbin/mtree/misc.c
cvs rdiff -u -r1.91 -r1.92 src/usr.sbin/mtree/spec.c
cvs rdiff -u -r1.48 -r1.49 src/usr.sbin/mtree/verify.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.sbin/mtree/compare.c
diff -u src/usr.sbin/mtree/compare.c:1.60 src/usr.sbin/mtree/compare.c:1.61
--- src/usr.sbin/mtree/compare.c:1.60 Sat Apr 3 09:37:18 2021
+++ src/usr.sbin/mtree/compare.c Thu Dec 5 12:17:43 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: compare.c,v 1.60 2021/04/03 13:37:18 simonb Exp $ */
+/* $NetBSD: compare.c,v 1.61 2024/12/05 17:17:43 christos Exp $ */
/*-
* Copyright (c) 1989, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)compare.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: compare.c,v 1.60 2021/04/03 13:37:18 simonb Exp $");
+__RCSID("$NetBSD: compare.c,v 1.61 2024/12/05 17:17:43 christos Exp $");
#endif
#endif /* not lint */
@@ -233,7 +233,7 @@ typeerr: LABEL;
"%suser expected %lu found %lu" : "%suser (%lu, %lu",
tab, (u_long)s->st_uid, (u_long)p->fts_statp->st_uid);
if (uflag) {
- if (lchown(p->fts_accpath, s->st_uid, -1))
+ if (lchown(p->fts_accpath, s->st_uid, (gid_t)-1))
printf(", not modified: %s%s\n",
strerror(errno),
flavor == F_FREEBSD9 ? "" : ")");
@@ -252,7 +252,7 @@ typeerr: LABEL;
"%sgid expected %lu found %lu" : "%sgid (%lu, %lu",
tab, (u_long)s->st_gid, (u_long)p->fts_statp->st_gid);
if (uflag) {
- if (lchown(p->fts_accpath, -1, s->st_gid))
+ if (lchown(p->fts_accpath, (uid_t)-1, s->st_gid))
printf(", not modified: %s%s\n",
strerror(errno),
flavor == F_FREEBSD9 ? "" : ")");
@@ -576,7 +576,7 @@ const char *
rlink(const char *name)
{
static char lbuf[MAXPATHLEN];
- int len;
+ ssize_t len;
if ((len = readlink(name, lbuf, sizeof(lbuf) - 1)) == -1)
mtree_err("%s: %s", name, strerror(errno));
Index: src/usr.sbin/mtree/crc.c
diff -u src/usr.sbin/mtree/crc.c:1.10 src/usr.sbin/mtree/crc.c:1.11
--- src/usr.sbin/mtree/crc.c:1.10 Thu Mar 18 16:02:18 2021
+++ src/usr.sbin/mtree/crc.c Thu Dec 5 12:17:43 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: crc.c,v 1.10 2021/03/18 20:02:18 cheusov Exp $ */
+/* $NetBSD: crc.c,v 1.11 2024/12/05 17:17:43 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)crc.c 8.1 (Berkeley) 6/17/93";
#else
-__RCSID("$NetBSD: crc.c,v 1.10 2021/03/18 20:02:18 cheusov Exp $");
+__RCSID("$NetBSD: crc.c,v 1.11 2024/12/05 17:17:43 christos Exp $");
#endif
#endif /* not lint */
@@ -114,13 +114,13 @@ static const uint32_t crctab[] = {
* locations to store the crc and the number of bytes read. It returns 0 on
* success and 1 on failure. Errno is set on failure.
*/
-uint32_t crc_total = ~0; /* The crc over a number of files. */
+uint32_t crc_total = ~0u; /* The crc over a number of files. */
int
crc(int fd, uint32_t *cval, uint32_t *clen)
{
u_char *p;
- int nr;
+ ssize_t nr;
uint32_t thecrc, len;
uint32_t crctot;
u_char buf[16 * 1024];
@@ -132,12 +132,12 @@ crc(int fd, uint32_t *cval, uint32_t *cl
crctot = ~crc_total;
while ((nr = read(fd, buf, sizeof(buf))) > 0)
if (sflag) {
- for (len += nr, p = buf; nr--; ++p) {
+ for (len += (uint32_t)nr, p = buf; nr--; ++p) {
COMPUTE(thecrc, *p);
COMPUTE(crctot, *p);
}
} else {
- for (len += nr, p = buf; nr--; ++p)
+ for (len += (uint32_t)nr, p = buf; nr--; ++p)
COMPUTE(thecrc, *p);
}
if (nr < 0)
Index: src/usr.sbin/mtree/create.c
diff -u src/usr.sbin/mtree/create.c:1.78 src/usr.sbin/mtree/create.c:1.79
--- src/usr.sbin/mtree/create.c:1.78 Tue Apr 23 21:44:51 2024
+++ src/usr.sbin/mtree/create.c Thu Dec 5 12:17:43 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: create.c,v 1.78 2024/04/24 01:44:51 christos Exp $ */
+/* $NetBSD: create.c,v 1.79 2024/12/05 17:17:43 christos Exp $ */
/*-
* Copyright (c) 1989, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)create.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: create.c,v 1.78 2024/04/24 01:44:51 christos Exp $");
+__RCSID("$NetBSD: create.c,v 1.79 2024/12/05 17:17:43 christos Exp $");
#endif
#endif /* not lint */
@@ -84,13 +84,6 @@ static uid_t uid;
static mode_t mode;
static u_long flags;
-#if defined(__FreeBSD__) && !defined(HAVE_NBTOOL_CONFIG_H)
-#define FTS_CONST const
-#else
-#define FTS_CONST
-#endif
-
-static int dcmp(const FTSENT *FTS_CONST *, const FTSENT *FTS_CONST *);
static void output(FILE *, int, int *, const char *, ...)
__printflike(4, 5);
static int statd(FILE *, FTS *, FTSENT *, uid_t *, gid_t *, mode_t *,
@@ -444,27 +437,6 @@ statd(FILE *fp, FTS *t, FTSENT *parent,
return (0);
}
-/*
- * dcmp --
- * used as a comparison function passed to fts_open() to control
- * the order in which fts_read() returns results. We make
- * directories sort after non-directories, but otherwise sort in
- * strcmp() order.
- *
- * Keep this in sync with nodecmp() in spec.c.
- */
-static int
-dcmp(const FTSENT *FTS_CONST *a, const FTSENT *FTS_CONST *b)
-{
-
- if (S_ISDIR((*a)->fts_statp->st_mode)) {
- if (!S_ISDIR((*b)->fts_statp->st_mode))
- return (1);
- } else if (S_ISDIR((*b)->fts_statp->st_mode))
- return (-1);
- return (strcmp((*a)->fts_name, (*b)->fts_name));
-}
-
void
output(FILE *fp, int indent, int *offset, const char *fmt, ...)
{
Index: src/usr.sbin/mtree/extern.h
diff -u src/usr.sbin/mtree/extern.h:1.40 src/usr.sbin/mtree/extern.h:1.41
--- src/usr.sbin/mtree/extern.h:1.40 Thu Mar 18 16:02:18 2021
+++ src/usr.sbin/mtree/extern.h Thu Dec 5 12:17:43 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.40 2021/03/18 20:02:18 cheusov Exp $ */
+/* $NetBSD: extern.h,v 1.41 2024/12/05 17:17:43 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -49,6 +49,12 @@
#include <netdb.h>
#endif
+#if defined(__FreeBSD__) && !defined(HAVE_NBTOOL_CONFIG_H)
+#define FTS_CONST const
+#else
+#define FTS_CONST
+#endif
+
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 256
#endif
@@ -64,6 +70,7 @@ int check_excludes(const char *, const
int compare(NODE *, FTSENT *);
int crc(int, uint32_t *, uint32_t *);
void cwalk(FILE *);
+int dcmp(const FTSENT *FTS_CONST *, const FTSENT *FTS_CONST *);
void dump_nodes(FILE *, const char *, NODE *, int);
void init_excludes(void);
int matchtags(NODE *);
Index: src/usr.sbin/mtree/misc.c
diff -u src/usr.sbin/mtree/misc.c:1.34 src/usr.sbin/mtree/misc.c:1.35
--- src/usr.sbin/mtree/misc.c:1.34 Thu Dec 20 14:09:25 2012
+++ src/usr.sbin/mtree/misc.c Thu Dec 5 12:17:43 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: misc.c,v 1.34 2012/12/20 19:09:25 christos Exp $ */
+/* $NetBSD: misc.c,v 1.35 2024/12/05 17:17:43 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: misc.c,v 1.34 2012/12/20 19:09:25 christos Exp $");
+__RCSID("$NetBSD: misc.c,v 1.35 2024/12/05 17:17:43 christos Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -111,7 +111,7 @@ slist_t excludetags, includetags;
int keys = KEYDEFAULT;
-int keycompare(const void *, const void *);
+static int keycompare(const void *, const void *);
u_int
parsekey(const char *name, int *needvaluep)
@@ -153,7 +153,7 @@ parsetype(const char *name)
return (k->val);
}
-int
+static int
keycompare(const void *a, const void *b)
{
@@ -198,7 +198,7 @@ void
parsetags(slist_t *list, char *args)
{
char *p, *e;
- int len;
+ size_t len;
if (args == NULL) {
addtag(list, NULL);
Index: src/usr.sbin/mtree/spec.c
diff -u src/usr.sbin/mtree/spec.c:1.91 src/usr.sbin/mtree/spec.c:1.92
--- src/usr.sbin/mtree/spec.c:1.91 Mon Nov 4 10:39:17 2024
+++ src/usr.sbin/mtree/spec.c Thu Dec 5 12:17:43 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: spec.c,v 1.91 2024/11/04 15:39:17 christos Exp $ */
+/* $NetBSD: spec.c,v 1.92 2024/12/05 17:17:43 christos Exp $ */
/*-
* Copyright (c) 1989, 1993
@@ -67,7 +67,7 @@
#if 0
static char sccsid[] = "@(#)spec.c 8.2 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: spec.c,v 1.91 2024/11/04 15:39:17 christos Exp $");
+__RCSID("$NetBSD: spec.c,v 1.92 2024/12/05 17:17:43 christos Exp $");
#endif
#endif /* not lint */
@@ -543,7 +543,8 @@ replacenode(NODE *cur, NODE *new)
static void
set(char *t, NODE *ip)
{
- int type, value, len;
+ int type, value;
+ size_t len;
gid_t gid;
uid_t uid;
char *kw, *val, *md, *ep;
@@ -842,7 +843,7 @@ addchild(NODE *pathparent, NODE *centry)
* directories sort after non-directories, but otherwise sort in
* strcmp() order.
*
- * Keep this in sync with dcmp() in create.c.
+ * Keep this in sync with dcmp() below.
*/
static int
nodecmp(const NODE *a, const NODE *b)
@@ -851,7 +852,30 @@ nodecmp(const NODE *a, const NODE *b)
if ((a->type & F_DIR) != 0) {
if ((b->type & F_DIR) == 0)
return 1;
- } else if ((b->type & F_DIR) != 0)
+ } else if ((b->type & F_DIR) != 0) {
return -1;
+ }
return strcmp(a->name, b->name);
}
+
+/*
+ * dcmp --
+ * used as a comparison function passed to fts_open() to control
+ * the order in which fts_read() returns results. We make
+ * directories sort after non-directories, but otherwise sort in
+ * strcmp() order.
+ *
+ * Keep this in sync with nodecmp() above.
+ */
+int
+dcmp(const FTSENT *FTS_CONST *a, const FTSENT *FTS_CONST *b)
+{
+
+ if (S_ISDIR((*a)->fts_statp->st_mode)) {
+ if (!S_ISDIR((*b)->fts_statp->st_mode))
+ return 1;
+ } else if (S_ISDIR((*b)->fts_statp->st_mode)) {
+ return -1;
+ }
+ return strcmp((*a)->fts_name, (*b)->fts_name);
+}
Index: src/usr.sbin/mtree/verify.c
diff -u src/usr.sbin/mtree/verify.c:1.48 src/usr.sbin/mtree/verify.c:1.49
--- src/usr.sbin/mtree/verify.c:1.48 Sat Dec 2 08:34:48 2023
+++ src/usr.sbin/mtree/verify.c Thu Dec 5 12:17:43 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: verify.c,v 1.48 2023/12/02 13:34:48 christos Exp $ */
+/* $NetBSD: verify.c,v 1.49 2024/12/05 17:17:43 christos Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)verify.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: verify.c,v 1.48 2023/12/02 13:34:48 christos Exp $");
+__RCSID("$NetBSD: verify.c,v 1.49 2024/12/05 17:17:43 christos Exp $");
#endif
#endif /* not lint */
@@ -86,7 +86,7 @@ vwalk(void)
argv[0] = dot;
argv[1] = NULL;
- if ((t = fts_open(argv, ftsoptions, NULL)) == NULL)
+ if ((t = fts_open(argv, ftsoptions, dcmp)) == NULL)
mtree_err("fts_open: %s", strerror(errno));
level = root;
specdepth = rval = 0;
@@ -180,7 +180,7 @@ miss(NODE *p, char *tail)
int create;
char *tp;
const char *type;
- uint32_t flags;
+ u_long flags;
for (; p; p = p->next) {
if (p->flags & F_OPT && !(p->flags & F_VISIT))