diff options
| author | Mattias Andrée <m@maandree.se> | 2026-05-14 22:20:02 +0200 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2026-05-14 22:20:02 +0200 |
| commit | f07a9f80fb6f3099d75534c1e64f448d4b397931 (patch) | |
| tree | 30ebf4afafb0e66226fa7f642db083341c8c96e4 /librecrypt_encode.c | |
| parent | librecrypt.h: add @since (diff) | |
| download | librecrypt-f07a9f80fb6f3099d75534c1e64f448d4b397931.tar.gz librecrypt-f07a9f80fb6f3099d75534c1e64f448d4b397931.tar.bz2 librecrypt-f07a9f80fb6f3099d75534c1e64f448d4b397931.tar.xz | |
Fix minor errors in the test and check that we are not writing out of bounds
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'librecrypt_encode.c')
| -rw-r--r-- | librecrypt_encode.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/librecrypt_encode.c b/librecrypt_encode.c index 6c81b33..ec371cc 100644 --- a/librecrypt_encode.c +++ b/librecrypt_encode.c @@ -156,17 +156,16 @@ check(const char *binary, size_t binary_len, const char *ascii, size_t ascii_len /* Check encoding requests, with and without truncation, without padding */ for (i = 0u; i <= ascii_len; i++) { - memset(buf, 99, sizeof(buf)); + CANARY_FILL(buf); EXPECT(librecrypt_encode(buf, i + 1u, binary, binary_len, lut, '\0') == ascii_len); EXPECT(!memcmp(buf, ascii, i)); EXPECT(buf[i] == '\0'); - for (j = i + 1u; j < sizeof(buf); j++) - EXPECT(buf[j] == 99); + CANARY_CHECK(buf, i + 1u); } /* Check encoding requests, with and without truncation, with padding */ for (i = 0u; i <= padded_ascii_len; i++) { - memset(buf, 99, sizeof(buf)); + CANARY_FILL(buf); EXPECT(librecrypt_encode(buf, i + 1u, binary, binary_len, lut, '=') == padded_ascii_len); j = MIN(i, ascii_len); n = MIN(i, padded_ascii_len); @@ -174,8 +173,7 @@ check(const char *binary, size_t binary_len, const char *ascii, size_t ascii_len for (; j < n; j++) EXPECT(buf[j] == '='); EXPECT(buf[j++] == '\0'); - for (; j < sizeof(buf); j++) - EXPECT(buf[j] == 99); + CANARY_CHECK(buf, j); } } |
