Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/cksum cksum.c: don't fault if the hash algorithm is ...



details:   https://anonhg.NetBSD.org/src/rev/59eed02346f9
branches:  trunk
changeset: 368124:59eed02346f9
user:      gutteridge <gutteridge%NetBSD.org@localhost>
date:      Sat Jun 25 02:22:42 2022 +0000

description:
cksum.c: don't fault if the hash algorithm is fed invalid data

Addresses PR bin/56897 from RVP, who provided the patch.

diffstat:

 usr.bin/cksum/cksum.c |  9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diffs (31 lines):

diff -r b98a680e0c98 -r 59eed02346f9 usr.bin/cksum/cksum.c
--- a/usr.bin/cksum/cksum.c     Sat Jun 25 01:54:37 2022 +0000
+++ b/usr.bin/cksum/cksum.c     Sat Jun 25 02:22:42 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cksum.c,v 1.51 2021/08/25 23:03:01 rillig Exp $        */
+/*     $NetBSD: cksum.c,v 1.52 2022/06/25 02:22:42 gutteridge Exp $    */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -81,7 +81,7 @@
 #if 0
 static char sccsid[] = "@(#)cksum.c    8.2 (Berkeley) 4/28/95";
 #endif
-__RCSID("$NetBSD: cksum.c,v 1.51 2021/08/25 23:03:01 rillig Exp $");
+__RCSID("$NetBSD: cksum.c,v 1.52 2022/06/25 02:22:42 gutteridge Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -421,8 +421,11 @@
                        strlcpy(cksum, p_cksum, l_cksum+1);
 
                        if (hash) {
+                               char *h;
+
                                if (access(filename, R_OK) == 0
-                                   && strcmp(cksum, hash->filefunc(filename, NULL)) == 0)
+                                   && (h = hash->filefunc(filename, NULL)) != NULL
+                                   && strcmp(cksum, h) == 0)
                                        ok = 1;
                                else
                                        ok = 0;



Home | Main Index | Thread Index | Old Index