summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2022-11-23 08:58:34 +0000
committertb <>2022-11-23 08:58:34 +0000
commitae543f04ebc807556c665f686245135f85ac3e8e (patch)
treec62b6129f2885b16faca733898bace78d2f3af0e
parentada8f63ac13903c0fcbae23ce5fc73ef9e984da5 (diff)
downloadopenbsd-ae543f04ebc807556c665f686245135f85ac3e8e.tar.gz
openbsd-ae543f04ebc807556c665f686245135f85ac3e8e.tar.bz2
openbsd-ae543f04ebc807556c665f686245135f85ac3e8e.zip
bn_unit: appease coverity
Apparently, the '0' in memset(a, '0', size - 1); could be a typo for '\0'. Randomize the decimal digit to make the intent clear. CID 377009
-rw-r--r--src/regress/lib/libcrypto/bn/general/bn_unit.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/regress/lib/libcrypto/bn/general/bn_unit.c b/src/regress/lib/libcrypto/bn/general/bn_unit.c
index f1a2c780f7..6ae6765998 100644
--- a/src/regress/lib/libcrypto/bn/general/bn_unit.c
+++ b/src/regress/lib/libcrypto/bn/general/bn_unit.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_unit.c,v 1.3 2022/11/23 08:01:05 tb Exp $ */ 1/* $OpenBSD: bn_unit.c,v 1.4 2022/11/23 08:58:34 tb Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2022 Theo Buehler <tb@openbsd.org> 4 * Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
@@ -45,6 +45,7 @@ test_bn_print_null_derefs(void)
45 size_t size = INT_MAX / 4 + 4; 45 size_t size = INT_MAX / 4 + 4;
46 size_t datalimit = (size + 500 * 1024) / 1024; 46 size_t datalimit = (size + 500 * 1024) / 1024;
47 char *a; 47 char *a;
48 char digit;
48 int failed = 0; 49 int failed = 0;
49 50
50 if ((a = malloc(size)) == NULL) { 51 if ((a = malloc(size)) == NULL) {
@@ -53,7 +54,10 @@ test_bn_print_null_derefs(void)
53 return 0; 54 return 0;
54 } 55 }
55 56
56 memset(a, '0', size - 1); 57 /* Fill with a random digit since coverity doesn't like us using '0'. */
58 digit = '0' + arc4random_uniform(10);
59
60 memset(a, digit, size - 1);
57 a[size - 1] = '\0'; 61 a[size - 1] = '\0';
58 62
59 failed |= test_bn_print_wrapper(a, size, "BN_dec2bn", BN_dec2bn); 63 failed |= test_bn_print_wrapper(a, size, "BN_dec2bn", BN_dec2bn);