Module Name:    src
Committed By:   joerg
Date:           Tue Jan 26 21:25:55 UTC 2021

Modified Files:
        src/usr.bin/nbperf: nbperf-bdz.c nbperf-chm.c

Log Message:
Fix potential off-by-one error when using hash fudging. It needs to
round up to 2/4 and not one less to guarantee that the adjusted hash
fits into array.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/nbperf/nbperf-bdz.c
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/nbperf/nbperf-chm.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/nbperf/nbperf-bdz.c
diff -u src/usr.bin/nbperf/nbperf-bdz.c:1.10 src/usr.bin/nbperf/nbperf-bdz.c:1.11
--- src/usr.bin/nbperf/nbperf-bdz.c:1.10	Thu Jan  7 16:03:08 2021
+++ src/usr.bin/nbperf/nbperf-bdz.c	Tue Jan 26 21:25:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: nbperf-bdz.c,v 1.10 2021/01/07 16:03:08 joerg Exp $	*/
+/*	$NetBSD: nbperf-bdz.c,v 1.11 2021/01/26 21:25:55 joerg Exp $	*/
 /*-
  * Copyright (c) 2009, 2012 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -36,7 +36,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: nbperf-bdz.c,v 1.10 2021/01/07 16:03:08 joerg Exp $");
+__RCSID("$NetBSD: nbperf-bdz.c,v 1.11 2021/01/26 21:25:55 joerg Exp $");
 
 #include <err.h>
 #include <inttypes.h>
@@ -285,7 +285,7 @@ bpz_compute(struct nbperf *nbperf)
 	if (v < 10)
 		v = 10;
 	if (nbperf->allow_hash_fudging)
-		v |= 3;
+		v = (v + 3) & ~3;
 
 	graph3_setup(&state.graph, v, e);
 

Index: src/usr.bin/nbperf/nbperf-chm.c
diff -u src/usr.bin/nbperf/nbperf-chm.c:1.4 src/usr.bin/nbperf/nbperf-chm.c:1.5
--- src/usr.bin/nbperf/nbperf-chm.c:1.4	Thu Jan  7 16:03:08 2021
+++ src/usr.bin/nbperf/nbperf-chm.c	Tue Jan 26 21:25:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: nbperf-chm.c,v 1.4 2021/01/07 16:03:08 joerg Exp $	*/
+/*	$NetBSD: nbperf-chm.c,v 1.5 2021/01/26 21:25:55 joerg Exp $	*/
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -35,7 +35,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: nbperf-chm.c,v 1.4 2021/01/07 16:03:08 joerg Exp $");
+__RCSID("$NetBSD: nbperf-chm.c,v 1.5 2021/01/26 21:25:55 joerg Exp $");
 
 #include <err.h>
 #include <inttypes.h>
@@ -262,12 +262,12 @@ chm_compute(struct nbperf *nbperf)
 	if (v < 10)
 		v = 10;
 	if (nbperf->allow_hash_fudging)
-		v |= 3;
+		v = (v + 3) & ~3;
 #else
 	if (v == 2 * nbperf->n)
 		++v;
 	if (nbperf->allow_hash_fudging)
-		v |= 1;
+		v = (v + 1) & ~1;
 #endif
 
 	state.g = calloc(sizeof(uint32_t), v);

Reply via email to