diff options
| author | Mattias Andrée <m@maandree.se> | 2026-05-16 10:47:00 +0200 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2026-05-16 10:47:00 +0200 |
| commit | dbffc7416c8463458d5049485fc838e33459089b (patch) | |
| tree | 65c508e7f6807db89b2fab1ed86ae0a489c4c2c6 | |
| parent | Add WITH_LIBAR2SIMPLIFIED=false + work on fuzzing code (diff) | |
| download | librecrypt-dbffc7416c8463458d5049485fc838e33459089b.tar.gz librecrypt-dbffc7416c8463458d5049485fc838e33459089b.tar.bz2 librecrypt-dbffc7416c8463458d5049485fc838e33459089b.tar.xz | |
Fix fuzzing code
Signed-off-by: Mattias Andrée <m@maandree.se>
| -rw-r--r-- | Makefile | 1 | ||||
| -rw-r--r-- | librecrypt_chain_length.c | 9 | ||||
| -rw-r--r-- | librecrypt_next_algorithm.c | 9 | ||||
| -rw-r--r-- | librecrypt_realise_salts.c | 1 |
4 files changed, 15 insertions, 5 deletions
@@ -93,6 +93,7 @@ all: librecrypt.a librecrypt.$(LIBEXT) $(TEST) $(OBJ): $(HDR) $(LOBJ): $(HDR) $(TOBJ): $(HDR) libtest/libtest.h +$(FOBJ): $(HDR) libtest/libtest.h $(TEST): $(HDR) librecrypt.a libtest/libtest.a libtest/libtest.h $(FUZZ): $(HDR) librecrypt.a libtest/libtest.a libtest/libtest.h diff --git a/librecrypt_chain_length.c b/librecrypt_chain_length.c index 364186a..adde62a 100644 --- a/librecrypt_chain_length.c +++ b/librecrypt_chain_length.c @@ -39,8 +39,13 @@ volatile size_t discarded_return_value; int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - (void) size; - discarded_return_value = librecrypt_chain_length((const void *)data); + char *hash; + hash = malloc(size + 1u); + assert(hash); + memcpy(hash, data, size); + hash[size] = '\0'; + discarded_return_value = librecrypt_chain_length(hash); + free(hash); return 0; } diff --git a/librecrypt_next_algorithm.c b/librecrypt_next_algorithm.c index 831f52e..623a19b 100644 --- a/librecrypt_next_algorithm.c +++ b/librecrypt_next_algorithm.c @@ -92,19 +92,22 @@ main(void) int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - char *hash, *r; - size_t sum = 0u; + char *hash, *orig, *r; + size_t sum = 0u, len; hash = malloc(size + 1u); assert(hash); + orig = hash; memcpy(hash, data, size); hash[size] = '\0'; + len = strlen(hash); for (;;) { r = librecrypt_next_algorithm(&hash); if (!r) break; sum += strlen(r) + 1u; } - EXPECT(sum == size + 1u); + EXPECT(sum == len + 1u); + free(orig); return 0; } diff --git a/librecrypt_realise_salts.c b/librecrypt_realise_salts.c index c7b7071..62bb2c3 100644 --- a/librecrypt_realise_salts.c +++ b/librecrypt_realise_salts.c @@ -367,6 +367,7 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) } free(out_buffer); + free(settings); return 0; } |
