binutils: addr2line: move preconditions to external header (#6803)

This commit is contained in:
DavidKorczynski 2021-11-09 15:09:14 +00:00 committed by GitHub
parent fb856de70b
commit 7efdd06e03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 65 deletions

View File

@ -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