Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/nbperf Fix potential off-by-one error when using has...



details:   https://anonhg.NetBSD.org/src/rev/18400f4a7a20
branches:  trunk
changeset: 958971:18400f4a7a20
user:      joerg <joerg%NetBSD.org@localhost>
date:      Tue Jan 26 21:25:55 2021 +0000

description:
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.

diffstat:

 usr.bin/nbperf/nbperf-bdz.c |  6 +++---
 usr.bin/nbperf/nbperf-chm.c |  8 ++++----
 2 files changed, 7 insertions(+), 7 deletions(-)

diffs (60 lines):

diff -r 29920928b080 -r 18400f4a7a20 usr.bin/nbperf/nbperf-bdz.c
--- a/usr.bin/nbperf/nbperf-bdz.c       Tue Jan 26 19:09:18 2021 +0000
+++ b/usr.bin/nbperf/nbperf-bdz.c       Tue Jan 26 21:25:55 2021 +0000
@@ -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 @@
        if (v < 10)
                v = 10;
        if (nbperf->allow_hash_fudging)
-               v |= 3;
+               v = (v + 3) & ~3;
 
        graph3_setup(&state.graph, v, e);
 
diff -r 29920928b080 -r 18400f4a7a20 usr.bin/nbperf/nbperf-chm.c
--- a/usr.bin/nbperf/nbperf-chm.c       Tue Jan 26 19:09:18 2021 +0000
+++ b/usr.bin/nbperf/nbperf-chm.c       Tue Jan 26 21:25:55 2021 +0000
@@ -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 @@
        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);



Home | Main Index | Thread Index | Old Index