aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2025-08-13 22:35:53 +0930
committerAlan Modra <amodra@gmail.com>2025-08-14 23:06:39 +0930
commitb3f31f8eea41213e264ddf673057d27bc9c155ea (patch)
treed3ceaaf21da2a9537367e7b4d877e2ec9652dc3f
parent9adb8ba865f2aebc6f4d7cc74df64ea200959b3a (diff)
downloadbinutils-b3f31f8eea41213e264ddf673057d27bc9c155ea.zip
binutils-b3f31f8eea41213e264ddf673057d27bc9c155ea.tar.gz
binutils-b3f31f8eea41213e264ddf673057d27bc9c155ea.tar.bz2
Recognise ECOFF armap in bfd_slurp_armap
Recognise ECOFF archives and reject them so that the ecoff archive support has a chance to handle the archive. Also use memcmp rather than startswith (strncmp) as we know the string length. * archive.c (bfd_slurp_armap): Recognize ECOFF armap. Use memcmp to match names, and tidy buffer sizes.
-rw-r--r--bfd/archive.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/bfd/archive.c b/bfd/archive.c
index 52d3119..be96bb2 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -1189,7 +1189,7 @@ do_slurp_coff_armap (bfd *abfd)
bool
bfd_slurp_armap (bfd *abfd)
{
- char nextname[17];
+ char nextname[16];
int i = bfd_read (nextname, 16, abfd);
if (i == 0)
@@ -1200,12 +1200,13 @@ bfd_slurp_armap (bfd *abfd)
if (bfd_seek (abfd, -16, SEEK_CUR) != 0)
return false;
- if (startswith (nextname, "__.SYMDEF ")
- || startswith (nextname, "__.SYMDEF/ ")) /* Old Linux archives. */
+ if (memcmp (nextname, "__.SYMDEF ", 16) == 0
+ /* Old Linux archives. */
+ || memcmp (nextname, "__.SYMDEF/ ", 16) == 0)
return do_slurp_bsd_armap (abfd);
- else if (startswith (nextname, "/ "))
+ else if (memcmp (nextname, "/ ", 16) == 0)
return do_slurp_coff_armap (abfd);
- else if (startswith (nextname, "/SYM64/ "))
+ else if (memcmp (nextname, "/SYM64/ ", 16) == 0)
{
/* 64bit (Irix 6) archive. */
#ifdef BFD64
@@ -1215,13 +1216,27 @@ bfd_slurp_armap (bfd *abfd)
return false;
#endif
}
- else if (startswith (nextname, "#1/20 "))
+ else if (memcmp (nextname, "________", 8) == 0
+ && ((nextname[8] == '_' && nextname[9] == '_')
+ || (nextname[8] == '6' && nextname[9] == '4'))
+ && nextname[10] == 'E'
+ && (nextname[11] == 'B' || nextname[11] == 'L')
+ && nextname[12] == 'E'
+ && (nextname[13] == 'B' || nextname[13] == 'L')
+ && nextname[14] == '_'
+ && (nextname[15] == ' ' || nextname[15] == 'X'))
+ {
+ /* ECOFF archive. */
+ bfd_set_error (bfd_error_wrong_format);
+ return false;
+ }
+ else if (memcmp (nextname, "#1/20 ", 16) == 0)
{
/* Mach-O has a special name for armap when the map is sorted by name.
However because this name has a space it is slightly more difficult
to check it. */
struct ar_hdr hdr;
- char extname[21];
+ char extname[20];
if (bfd_read (&hdr, sizeof (hdr), abfd) != sizeof (hdr))
return false;
@@ -1230,9 +1245,8 @@ bfd_slurp_armap (bfd *abfd)
return false;
if (bfd_seek (abfd, -(file_ptr) (sizeof (hdr) + 20), SEEK_CUR) != 0)
return false;
- extname[20] = 0;
- if (startswith (extname, "__.SYMDEF SORTED")
- || startswith (extname, "__.SYMDEF"))
+ if (memcmp (extname, "__.SYMDEF SORTED", 16) == 0
+ || memcmp (extname, "__.SYMDEF", 9) == 0)
return do_slurp_bsd_armap (abfd);
}