From 81b85b557c308ff743b7b83f2b823e508eef54eb Mon Sep 17 00:00:00 2001 From: ame Date: Wed, 1 May 2024 23:52:54 -0500 Subject: fix some hash ub --- src/hash/blake.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/hash/blake.c') diff --git a/src/hash/blake.c b/src/hash/blake.c index c6d73ad..76b6680 100644 --- a/src/hash/blake.c +++ b/src/hash/blake.c @@ -215,7 +215,7 @@ void blake256_final(struct blake256_hash* hash, char* out_stream){ _blake256_final(hash, out_stream); for(int i = 0; i != 8; i++){ - sprintf(out_stream, "%s%08x",out_stream,(hash->hash)[i]); + sprintf(out_stream + i * 8, "%08x",(hash->hash)[i]); } memcpy(hash, &old_hash, sizeof * hash); @@ -234,7 +234,7 @@ void blake224_final(struct blake256_hash* hash, char* out_stream){ _blake256_final(hash, out_stream); for(int i = 0; i != 7; i++){ - sprintf(out_stream, "%s%08x",out_stream,(hash->hash)[i]); + sprintf(out_stream + i * 8, "%08x",(hash->hash)[i]); } memcpy(hash, &old_hash, sizeof * hash); @@ -427,8 +427,8 @@ void blake512_final(struct blake512_hash* hash, char* out_stream){ _blake512_final(hash, out_stream); for(int i = 0; i != 8; i++){ - sprintf(out_stream, "%s%016llx",out_stream, (hash->hash)[i]); - } + sprintf(out_stream + 16 * i, "%016llx", (hash->hash)[i]); + } memcpy(hash, &old_hash, sizeof * hash); memcpy(hash->buffer, old, bs_2); @@ -454,8 +454,8 @@ void blake384_final(struct blake384_hash* hash, char* out_stream){ _blake512_final(hash, out_stream); for(int i = 0; i != 6; i++){ - sprintf(out_stream, "%s%016llx",out_stream, (hash->hash)[i]); - } + sprintf(out_stream + 16 * i, "%016llx", (hash->hash)[i]); + } memcpy(hash, &old_hash, sizeof * hash); memcpy(hash->buffer, old, bs_2); -- cgit v1.2.3