From 7efdd06e03c4c7e4867b25a3658d177bc94b472e Mon Sep 17 00:00:00 2001 From: DavidKorczynski Date: Tue, 9 Nov 2021 15:09:14 +0000 Subject: [PATCH] binutils: addr2line: move preconditions to external header (#6803) --- projects/binutils/fuzz_addr2line.c | 68 ++---------------------------- 1 file changed, 3 insertions(+), 65 deletions(-) diff --git a/projects/binutils/fuzz_addr2line.c b/projects/binutils/fuzz_addr2line.c index 786106f6e..c6fc20d3a 100644 --- a/projects/binutils/fuzz_addr2line.c +++ b/projects/binutils/fuzz_addr2line.c @@ -17,6 +17,9 @@ limitations under the License. */ #include "fuzz_addr2line.h" +/* for precondition checks */ +#include "ada_addr2line.h" + /* * Preconditions that should be met so we won't run into bfd_fatal calls. * The fuzz_slurp_symtab and fuzz_preconditions_check implement simplified @@ -26,71 +29,6 @@ limitations under the License. * good to be called and there won't be any bfd_fatal call. */ -int fuzz_slurp_symtab(bfd *abfd) { - long storage; - long symcount; - bool dynamic = false; - - if ((bfd_get_file_flags (abfd) & HAS_SYMS) == 0) { - return 1; - } - storage = bfd_get_symtab_upper_bound (abfd); - if (storage == 0) { - storage = bfd_get_dynamic_symtab_upper_bound (abfd); - dynamic = true; - } - if (storage < 0) { - return 0; - } - - syms = (asymbol **) xmalloc (storage); - if (dynamic) { - symcount = bfd_canonicalize_dynamic_symtab (abfd, syms); - } - else { - symcount = bfd_canonicalize_symtab (abfd, syms); - } - - if (symcount < 0) { - free(syms); - syms = NULL; - return 0; - } - free(syms); - syms = NULL; - return 1; -} - -int fuzz_preconditions_check(const char *file_name, const char *target) { - bfd *abfd; - char **matching; - - if (get_file_size (file_name) < 1) { - return 0; - } - - abfd = bfd_openr (file_name, target); - if (abfd == NULL) { - /* In this specific case just exit the fuzzer */ - bfd_fatal (file_name); - } - - abfd->flags |= BFD_DECOMPRESS; - if (bfd_check_format (abfd, bfd_archive)) { - bfd_close(abfd); - return 0; - } - - if (! bfd_check_format_matches (abfd, bfd_object, &matching)) { - bfd_close(abfd); - return 0; - } - - /* Check if slurp_symtab will exit */ - int retval = fuzz_slurp_symtab(abfd); - bfd_close(abfd); - return retval; -} int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size); int