From f07a9f80fb6f3099d75534c1e64f448d4b397931 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 14 May 2026 22:20:02 +0200 Subject: Fix minor errors in the test and check that we are not writing out of bounds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- librecrypt_decode.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'librecrypt_decode.c') diff --git a/librecrypt_decode.c b/librecrypt_decode.c index 3981612..5d09efa 100644 --- a/librecrypt_decode.c +++ b/librecrypt_decode.c @@ -184,34 +184,30 @@ check(const char *binary, size_t binary_len, const char *ascii, size_t unpadded_ /* Test output, with and without truncation */ for (i = 0u; i < sizeof(buf); i++) { - memset(buf, 99, sizeof(buf)); + CANARY_FILL(buf); EXPECT(librecrypt_decode(buf, i, ascii, unpadded_len, lut, '\0', 0) == (ssize_t)binary_len); j = MIN(i, binary_len); EXPECT(!memcmp(buf, binary, j)); - for (; j < sizeof(buf); j++) - EXPECT(buf[j] == 99); + CANARY_CHECK(buf, j); - memset(buf, 99, sizeof(buf)); + CANARY_FILL(buf); EXPECT(librecrypt_decode(buf, i, ascii, unpadded_len, lut, '\0', 1) == (ssize_t)binary_len); j = MIN(i, binary_len); EXPECT(!memcmp(buf, binary, j)); - for (; j < sizeof(buf); j++) - EXPECT(buf[j] == 99); + CANARY_CHECK(buf, j); - memset(buf, 99, sizeof(buf)); + CANARY_FILL(buf); EXPECT(librecrypt_decode(buf, i, ascii, unpadded_len, lut, '=', 0) == (ssize_t)binary_len); j = MIN(i, binary_len); EXPECT(!memcmp(buf, binary, j)); - for (; j < sizeof(buf); j++) - EXPECT(buf[j] == 99); + CANARY_CHECK(buf, j); if (padded_len == unpadded_len) { - memset(buf, 99, sizeof(buf)); + CANARY_FILL(buf); EXPECT(librecrypt_decode(buf, i, ascii, unpadded_len, lut, '=', 1) == (ssize_t)binary_len); j = MIN(i, binary_len); EXPECT(!memcmp(buf, binary, j)); - for (; j < sizeof(buf); j++) - EXPECT(buf[j] == 99); + CANARY_CHECK(buf, j); } else { errno = 0; EXPECT(librecrypt_decode(buf, i, ascii, unpadded_len, lut, '=', 1) == -1); @@ -226,20 +222,18 @@ check(const char *binary, size_t binary_len, const char *ascii, size_t unpadded_ EXPECT(errno == EINVAL); } - memset(buf, 99, sizeof(buf)); + CANARY_FILL(buf); EXPECT(librecrypt_decode(buf, i, ascii, padded_len, lut, '=', 0) == (ssize_t)binary_len); j = MIN(i, binary_len); EXPECT(!memcmp(buf, binary, j)); - for (; j < sizeof(buf); j++) - EXPECT(buf[j] == 99); + CANARY_CHECK(buf, j); if (check_good_padding) { - memset(buf, 99, sizeof(buf)); + CANARY_FILL(buf); EXPECT(librecrypt_decode(buf, i, ascii, padded_len, lut, '=', 1) == (ssize_t)binary_len); j = MIN(i, binary_len); EXPECT(!memcmp(buf, binary, j)); - for (; j < sizeof(buf); j++) - EXPECT(buf[j] == 99); + CANARY_CHECK(buf, j); } } -- cgit v1.2.3-70-g09d2