From 900e1a78c71aeba3ec72eb3bac6ce863f563a449 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 21 Jan 2022 16:31:52 +0100 Subject: Fix memory corruption bug in test.c and simplify message byte-length calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test.c') diff --git a/test.c b/test.c index 6205d4e..a6e6475 100644 --- a/test.c +++ b/test.c @@ -35,7 +35,7 @@ check_hex(int uppercase, const char *hex, const unsigned char *bin, size_t n) static const char * digest_blake1(int length, const void *msg, size_t msglen, size_t bits) { - static char hex[sizeof(LIBBLAKE_BLAKE512_OUTPUT_SIZE) * 2 + 1]; + static char hex[LIBBLAKE_BLAKE512_OUTPUT_SIZE * 2 + 1]; unsigned char buf[LIBBLAKE_BLAKE512_OUTPUT_SIZE]; size_t req; char *data; @@ -45,7 +45,7 @@ digest_blake1(int length, const void *msg, size_t msglen, size_t bits) struct libblake_blake##BITS##_state s##BITS;\ req = libblake_blake##BITS##_digest_get_required_input_size(msglen, bits, NULL);\ data = malloc(req);\ - memcpy(data, msg, msglen + bits / 8 + !!(bits & 7));\ + memcpy(data, msg, msglen + (bits + 7) / 8);\ libblake_blake##BITS##_init(&s##BITS);\ libblake_blake##BITS##_digest(&s##BITS, data, msglen, bits, NULL, buf);\ libblake_encode_hex(buf, LIBBLAKE_BLAKE##BITS##_OUTPUT_SIZE, hex, 0);\ -- cgit v1.2.3-70-g09d2