};
/* Information about one member of an archive. */
-struct member_layout {
+struct member_layout
+{
/* The archive member that this structure describes. */
bfd *member;
};
/* A structure used for iterating over the members of an archive. */
-struct archive_iterator {
+struct archive_iterator
+{
/* The archive itself. */
bfd *archive;
end:
return bfd_coff_auxesz (abfd);
}
-
-
\f
/* The XCOFF reloc table. Actually, XCOFF relocations specify the
bitsize and whether they are signed or not, along with a
different algorithms for putting in the reloc. Many of these
relocs need special_function entries, which I have not written. */
-
reloc_howto_type xcoff_howto_table[] =
{
/* 0x00: Standard 32 bit relocation. */
/* bfd_xcoff_archive_set_magic (abfd, magic); */
}
+/* PR 21786: The PE/COFF standard does not require NUL termination for any of
+ the ASCII fields in the archive headers. So in order to be able to extract
+ numerical values we provide our own versions of strtol and strtoll which
+ take a maximum length as an additional parameter. Also - just to save space,
+ we omit the endptr return parameter, since we know that it is never used. */
+
+static long
+_bfd_strntol (const char * nptr, int base, unsigned int maxlen)
+{
+ char buf[24]; /* Should be enough. */
+
+ BFD_ASSERT (maxlen < (sizeof (buf) - 1));
+
+ memcpy (buf, nptr, maxlen);
+ buf[maxlen] = 0;
+ return strtol (buf, NULL, base);
+}
+
+static long long
+_bfd_strntoll (const char * nptr, int base, unsigned int maxlen)
+{
+ char buf[32]; /* Should be enough. */
+
+ BFD_ASSERT (maxlen < (sizeof (buf) - 1));
+
+ memcpy (buf, nptr, maxlen);
+ buf[maxlen] = 0;
+ return strtoll (buf, NULL, base);
+}
+
+/* Macro to read an ASCII value stored in an archive header field. */
+#define GET_VALUE_IN_FIELD(VAR, FIELD) \
+ do \
+ { \
+ (VAR) = sizeof (VAR) > sizeof (long) \
+ ? _bfd_strntoll (FIELD, 10, sizeof FIELD) \
+ : _bfd_strntol (FIELD, 10, sizeof FIELD); \
+ } \
+ while (0)
+
+#define EQ_VALUE_IN_FIELD(VAR, FIELD) \
+ (sizeof (VAR) > sizeof (long) \
+ ? (VAR) ==_bfd_strntoll (FIELD, 10, sizeof FIELD) \
+ : (VAR) == _bfd_strntol (FIELD, 10, sizeof FIELD))
+
/* Read in the armap of an XCOFF archive. */
bfd_boolean
/* This is for the old format. */
struct xcoff_ar_hdr hdr;
- off = strtol (xcoff_ardata (abfd)->symoff, (char **) NULL, 10);
+ GET_VALUE_IN_FIELD (off, xcoff_ardata (abfd)->symoff);
if (off == 0)
{
bfd_has_map (abfd) = FALSE;
return FALSE;
/* Skip the name (normally empty). */
- namlen = strtol (hdr.namlen, (char **) NULL, 10);
+ GET_VALUE_IN_FIELD (namlen, hdr.namlen);
off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
if (bfd_seek (abfd, off, SEEK_CUR) != 0)
return FALSE;
- sz = strtol (hdr.size, (char **) NULL, 10);
+ GET_VALUE_IN_FIELD (sz, hdr.size);
/* Read in the entire symbol table. */
contents = (bfd_byte *) bfd_alloc (abfd, sz);
/* This is for the new format. */
struct xcoff_ar_hdr_big hdr;
- off = strtol (xcoff_ardata_big (abfd)->symoff, (char **) NULL, 10);
+ GET_VALUE_IN_FIELD (off, xcoff_ardata_big (abfd)->symoff);
if (off == 0)
{
bfd_has_map (abfd) = FALSE;
return FALSE;
/* Skip the name (normally empty). */
- namlen = strtol (hdr.namlen, (char **) NULL, 10);
+ GET_VALUE_IN_FIELD (namlen, hdr.namlen);
off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
if (bfd_seek (abfd, off, SEEK_CUR) != 0)
return FALSE;
- /* XXX This actually has to be a call to strtoll (at least on 32-bit
- machines) since the field width is 20 and there numbers with more
- than 32 bits can be represented. */
- sz = strtol (hdr.size, (char **) NULL, 10);
+ GET_VALUE_IN_FIELD (sz, hdr.size);
/* Read in the entire symbol table. */
contents = (bfd_byte *) bfd_alloc (abfd, sz);
goto error_ret;
}
- bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
- (char **) NULL, 10);
+ GET_VALUE_IN_FIELD (bfd_ardata (abfd)->first_file_filepos,
+ hdr.firstmemoff);
amt = SIZEOF_AR_FILE_HDR;
bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
return NULL;
}
- namlen = strtol (hdr.namlen, (char **) NULL, 10);
+ GET_VALUE_IN_FIELD (namlen, hdr.namlen);
amt = SIZEOF_AR_HDR + namlen + 1;
hdrp = (struct xcoff_ar_hdr *) bfd_alloc (abfd, amt);
if (hdrp == NULL)
((char *) hdrp)[SIZEOF_AR_HDR + namlen] = '\0';
ret->arch_header = (char *) hdrp;
- ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
+ GET_VALUE_IN_FIELD (ret->parsed_size, hdr.size);
ret->filename = (char *) hdrp + SIZEOF_AR_HDR;
}
else
return NULL;
}
- namlen = strtol (hdr.namlen, (char **) NULL, 10);
+ GET_VALUE_IN_FIELD (namlen, hdr.namlen);
amt = SIZEOF_AR_HDR_BIG + namlen + 1;
hdrp = (struct xcoff_ar_hdr_big *) bfd_alloc (abfd, amt);
if (hdrp == NULL)
((char *) hdrp)[SIZEOF_AR_HDR_BIG + namlen] = '\0';
ret->arch_header = (char *) hdrp;
- /* XXX This actually has to be a call to strtoll (at least on 32-bit
- machines) since the field width is 20 and there numbers with more
- than 32 bits can be represented. */
- ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
+ GET_VALUE_IN_FIELD (ret->parsed_size, hdr.size);
ret->filename = (char *) hdrp + SIZEOF_AR_HDR_BIG;
}
if (last_file == NULL)
filestart = bfd_ardata (archive)->first_file_filepos;
else
- filestart = strtol (arch_xhdr (last_file)->nextoff, (char **) NULL,
- 10);
+ GET_VALUE_IN_FIELD (filestart, arch_xhdr (last_file)->nextoff);
if (filestart == 0
- || filestart == strtol (xcoff_ardata (archive)->memoff,
- (char **) NULL, 10)
- || filestart == strtol (xcoff_ardata (archive)->symoff,
- (char **) NULL, 10))
+ || EQ_VALUE_IN_FIELD (filestart, xcoff_ardata (archive)->memoff)
+ || EQ_VALUE_IN_FIELD (filestart, xcoff_ardata (archive)->symoff))
{
bfd_set_error (bfd_error_no_more_archived_files);
return NULL;
if (last_file == NULL)
filestart = bfd_ardata (archive)->first_file_filepos;
else
- /* XXX These actually have to be a calls to strtoll (at least
- on 32-bit machines) since the fields's width is 20 and
- there numbers with more than 32 bits can be represented. */
- filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL,
- 10);
-
- /* XXX These actually have to be calls to strtoll (at least on 32-bit
- machines) since the fields's width is 20 and there numbers with more
- than 32 bits can be represented. */
+ GET_VALUE_IN_FIELD (filestart, arch_xhdr_big (last_file)->nextoff);
+
if (filestart == 0
- || filestart == strtol (xcoff_ardata_big (archive)->memoff,
- (char **) NULL, 10)
- || filestart == strtol (xcoff_ardata_big (archive)->symoff,
- (char **) NULL, 10))
+ || EQ_VALUE_IN_FIELD (filestart, xcoff_ardata_big (archive)->memoff)
+ || EQ_VALUE_IN_FIELD (filestart, xcoff_ardata_big (archive)->symoff))
{
bfd_set_error (bfd_error_no_more_archived_files);
return NULL;
{
struct xcoff_ar_hdr *hdrp = arch_xhdr (abfd);
- s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
- s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
- s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
- s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
+ GET_VALUE_IN_FIELD (s->st_mtime, hdrp->date);
+ GET_VALUE_IN_FIELD (s->st_uid, hdrp->uid);
+ GET_VALUE_IN_FIELD (s->st_gid, hdrp->gid);
+ GET_VALUE_IN_FIELD (s->st_mode, hdrp->mode);
s->st_size = arch_eltdata (abfd)->parsed_size;
}
else
{
struct xcoff_ar_hdr_big *hdrp = arch_xhdr_big (abfd);
- s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
- s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
- s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
- s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
+ GET_VALUE_IN_FIELD (s->st_mtime, hdrp->date);
+ GET_VALUE_IN_FIELD (s->st_uid, hdrp->uid);
+ GET_VALUE_IN_FIELD (s->st_gid, hdrp->gid);
+ GET_VALUE_IN_FIELD (s->st_mode, hdrp->mode);
s->st_size = arch_eltdata (abfd)->parsed_size;
}