From efb261a95c5a81ddb148f205d74eab3714155f0d Mon Sep 17 00:00:00 2001 From: Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> Date: Mon, 29 May 2023 19:24:00 +0200 Subject: Fix some memory errors triggered by allocation failures (#1995) Some low hanging fruits found using nallocfuzz. See: https://github.com/catenacyber/nallocfuzz See: https://github.com/google/oss-fuzz/pull/9902 Most of these errors are quite trivial to fix; the only exception is the stuff in the uthash. If the insertion fails (because of an allocation failure), we need to avoid some memory leaks. But the only way to check if the `HASH_ADD_*` failed, is to perform a new lookup: a bit costly, but we don't use that code in any critical data-path. --- fuzz/fuzz_libinjection.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'fuzz/fuzz_libinjection.c') diff --git a/fuzz/fuzz_libinjection.c b/fuzz/fuzz_libinjection.c index c878fe823..f614a62e1 100644 --- a/fuzz/fuzz_libinjection.c +++ b/fuzz/fuzz_libinjection.c @@ -12,6 +12,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { /* Libinjection: it wants null-terminated string */ query = malloc(size + 1); + if (!query) + return 0; memcpy(query, data, size); query[size] = '\0'; -- cgit v1.2.3