aboutsummaryrefslogtreecommitdiff
path: root/bfd/pef.c
diff options
context:
space:
mode:
Diffstat (limited to 'bfd/pef.c')
-rw-r--r--bfd/pef.c62
1 files changed, 29 insertions, 33 deletions
diff --git a/bfd/pef.c b/bfd/pef.c
index f330b92..23d26b0 100644
--- a/bfd/pef.c
+++ b/bfd/pef.c
@@ -1,5 +1,5 @@
/* PEF support for BFD.
- Copyright (C) 1999-2024 Free Software Foundation, Inc.
+ Copyright (C) 1999-2025 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
@@ -210,16 +210,18 @@ bfd_pef_print_symbol (bfd *abfd,
bfd_print_symbol_type how)
{
FILE *file = (FILE *) afile;
+ const char *symname = (symbol->name != bfd_symbol_error_name
+ ? symbol->name : _("<corrupt>"));
switch (how)
{
case bfd_print_symbol_name:
- fprintf (file, "%s", symbol->name);
+ fprintf (file, "%s", symname);
break;
default:
bfd_print_symbol_vandf (abfd, (void *) file, symbol);
- fprintf (file, " %-5s %s", symbol->section->name, symbol->name);
- if (startswith (symbol->name, "__traceback_"))
+ fprintf (file, " %-5s %s", symbol->section->name, symname);
+ if (startswith (symname, "__traceback_"))
{
unsigned char *buf;
size_t offset = symbol->value + 4;
@@ -481,7 +483,7 @@ bfd_pef_scan_start_address (bfd *abfd)
loaderlen = loadersec->size;
if (loaderlen < 56)
- goto error;
+ goto wrong;
if (bfd_seek (abfd, loadersec->filepos, SEEK_SET) != 0)
goto error;
loaderbuf = _bfd_malloc_and_read (abfd, loaderlen, loaderlen);
@@ -490,7 +492,7 @@ bfd_pef_scan_start_address (bfd *abfd)
ret = bfd_pef_parse_loader_header (abfd, loaderbuf, 56, &header);
if (ret < 0)
- goto error;
+ goto wrong;
if (header.main_section < 0)
goto end;
@@ -500,7 +502,7 @@ bfd_pef_scan_start_address (bfd *abfd)
break;
if (section == NULL)
- goto error;
+ goto wrong;
abfd->start_address = section->vma + header.main_offset;
@@ -508,6 +510,8 @@ bfd_pef_scan_start_address (bfd *abfd)
free (loaderbuf);
return 0;
+ wrong:
+ bfd_set_error (bfd_error_wrong_format);
error:
free (loaderbuf);
return -1;
@@ -557,8 +561,6 @@ bfd_pef_scan (bfd *abfd,
if (bfd_pef_scan_start_address (abfd) < 0)
return -1;
- abfd->tdata.pef_data = mdata;
-
return 0;
}
@@ -593,25 +595,26 @@ bfd_pef_object_p (bfd *abfd)
bfd_pef_data_struct *mdata;
if (bfd_pef_read_header (abfd, &header) != 0)
- goto wrong;
+ return NULL;
if (header.tag1 != BFD_PEF_TAG1 || header.tag2 != BFD_PEF_TAG2)
- goto wrong;
+ {
+ bfd_set_error (bfd_error_wrong_format);
+ return NULL;
+ }
mdata = (bfd_pef_data_struct *) bfd_zalloc (abfd, sizeof (*mdata));
if (mdata == NULL)
- goto fail;
+ return NULL;
if (bfd_pef_scan (abfd, &header, mdata))
- goto wrong;
+ {
+ bfd_release (abfd, mdata);
+ return NULL;
+ }
+ abfd->tdata.pef_data = mdata;
return _bfd_no_cleanup;
-
- wrong:
- bfd_set_error (bfd_error_wrong_format);
-
- fail:
- return NULL;
}
static int
@@ -1121,25 +1124,18 @@ bfd_pef_xlib_object_p (bfd *abfd)
{
bfd_pef_xlib_header header;
- if (bfd_pef_xlib_read_header (abfd, &header) != 0)
+ if (bfd_pef_xlib_read_header (abfd, &header) != 0
+ || header.tag1 != BFD_PEF_XLIB_TAG1
+ || (header.tag2 != BFD_PEF_VLIB_TAG2
+ && header.tag2 != BFD_PEF_BLIB_TAG2))
{
- bfd_set_error (bfd_error_wrong_format);
- return NULL;
- }
-
- if ((header.tag1 != BFD_PEF_XLIB_TAG1)
- || ((header.tag2 != BFD_PEF_VLIB_TAG2)
- && (header.tag2 != BFD_PEF_BLIB_TAG2)))
- {
- bfd_set_error (bfd_error_wrong_format);
+ if (bfd_get_error () != bfd_error_system_call)
+ bfd_set_error (bfd_error_wrong_format);
return NULL;
}
if (bfd_pef_xlib_scan (abfd, &header) != 0)
- {
- bfd_set_error (bfd_error_wrong_format);
- return NULL;
- }
+ return NULL;
return _bfd_no_cleanup;
}