Skip to content

Commit 07d6d75

Browse files
author
Lealem Amedie
committed
Fix for sanitizer finds
1 parent 2c72484 commit 07d6d75

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

wolfcrypt/benchmark/benchmark.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2676,6 +2676,7 @@ static void* benchmarks_do(void* args)
26762676

26772677
#ifndef NO_FILESYSTEM
26782678
if (hash_input) {
2679+
int rawSz;
26792680
XFILE file;
26802681
file = XFOPEN(hash_input, "rb");
26812682
if (file == XBADFILE)
@@ -2694,14 +2695,20 @@ static void* benchmarks_do(void* args)
26942695

26952696
XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
26962697

2697-
bench_plain = (byte*)XMALLOC((size_t)bench_buf_size,
2698+
rawSz = bench_buf_size;
2699+
if (bench_buf_size % 16)
2700+
bench_buf_size += 16 - (bench_buf_size % 16);
2701+
2702+
bench_size = bench_buf_size;
2703+
2704+
bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
26982705
HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
26992706

27002707
if (bench_plain == NULL)
27012708
goto exit;
27022709

2703-
if ((size_t)XFREAD(bench_plain, 1, bench_buf_size, file)
2704-
!= (size_t)bench_buf_size) {
2710+
if ((size_t)XFREAD(bench_plain, 1, rawSz, file)
2711+
!= (size_t)rawSz) {
27052712
XFCLOSE(file);
27062713
goto exit;
27072714
}
@@ -2711,6 +2718,7 @@ static void* benchmarks_do(void* args)
27112718
}
27122719

27132720
if (cipher_input) {
2721+
int rawSz;
27142722
XFILE file;
27152723
file = XFOPEN(cipher_input, "rb");
27162724
if (file == XBADFILE)
@@ -2729,14 +2737,21 @@ static void* benchmarks_do(void* args)
27292737

27302738
XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
27312739

2732-
bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size,
2740+
rawSz = bench_buf_size;
2741+
if (bench_buf_size % 16)
2742+
bench_buf_size += 16 - (bench_buf_size % 16);
2743+
2744+
if (bench_size > bench_buf_size)
2745+
bench_size = bench_buf_size;
2746+
2747+
bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
27332748
HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
27342749

27352750
if (bench_cipher == NULL)
27362751
goto exit;
27372752

2738-
if ((size_t)XFREAD(bench_cipher, 1, bench_buf_size, file)
2739-
!= (size_t)bench_buf_size) {
2753+
if ((size_t)XFREAD(bench_cipher, 1, rawSz, file)
2754+
!= (size_t)rawSz) {
27402755
XFCLOSE(file);
27412756
goto exit;
27422757
}
@@ -4351,9 +4366,9 @@ static void bench_aesecb_internal(int useDeviceID,
43514366
double start;
43524367
DECLARE_MULTI_VALUE_STATS_VARS()
43534368
#ifdef HAVE_FIPS
4354-
static const int benchSz = AES_BLOCK_SIZE;
4369+
const int benchSz = AES_BLOCK_SIZE;
43554370
#else
4356-
static const int benchSz = BENCH_SIZE;
4371+
const int benchSz = (const int)bench_size;
43574372
#endif
43584373

43594374
/* clear for done cleanup */

0 commit comments

Comments
 (0)