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
+static unsigned long
_bfd_strntol (const char * nptr, int base, unsigned int maxlen)
{
char buf[24]; /* Should be enough. */
return strtol (buf, NULL, base);
}
-static long long
+static unsigned long long
_bfd_strntoll (const char * nptr, int base, unsigned int maxlen)
{
char buf[32]; /* Should be enough. */
bool
_bfd_xcoff_slurp_armap (bfd *abfd)
{
- file_ptr off;
+ ufile_ptr off;
size_t namlen;
bfd_size_type sz;
bfd_byte *contents, *cend;
/* Overlap with another element. */
goto err;
- unsigned min_elt = x_artdata (abfd)->min_elt;
+ /* A zero size element with a one char name is this big. */
+ unsigned min_elt = x_artdata (abfd)->ar_hdr_size + 2 + SXCOFFARFMAG;
if (start - lo->end < min_elt)
{
/* Merge into an existing range. */
bfd *
_bfd_xcoff_openr_next_archived_file (bfd *archive, bfd *last_file)
{
- file_ptr filestart;
+ ufile_ptr filestart;
if (x_artdata (archive) == NULL)
{
if (last_file == NULL)
{
filestart = bfd_ardata (archive)->first_file_filepos;
- if (x_artdata (archive)->min_elt == 0)
+ if (x_artdata (archive)->ar_hdr_size == 0)
{
x_artdata (archive)->ranges.end = SIZEOF_AR_FILE_HDR;
- x_artdata (archive)->min_elt = SIZEOF_AR_HDR + SXCOFFARFMAG + 2;
+ x_artdata (archive)->ar_hdr_size = SIZEOF_AR_HDR;
}
}
else
if (last_file == NULL)
{
filestart = bfd_ardata (archive)->first_file_filepos;
- if (x_artdata (archive)->min_elt == 0)
+ if (x_artdata (archive)->ar_hdr_size == 0)
{
x_artdata (archive)->ranges.end = SIZEOF_AR_FILE_HDR_BIG;
- x_artdata (archive)->min_elt = SIZEOF_AR_HDR_BIG + SXCOFFARFMAG + 2;
+ x_artdata (archive)->ar_hdr_size = SIZEOF_AR_HDR_BIG;
}
}
else
}
}
+ /* Check that we aren't pointing back at the last element. This is
+ necessary depite the add_range checking in _bfd_xcoff_read_ar_hdr
+ because archive.c leaves the last element open and thus in the
+ archive element cache until the next element is opened. */
+ if (last_file != NULL)
+ {
+ ufile_ptr laststart = last_file->proxy_origin;
+ laststart -= x_artdata (archive)->ar_hdr_size;
+ laststart -= arch_eltdata (last_file)->extra_size;
+ if (filestart == laststart)
+ {
+ bfd_set_error (bfd_error_malformed_archive);
+ return NULL;
+ }
+ }
+
return _bfd_get_elt_at_filepos (archive, filestart, NULL);
}
} u;
struct ar_ranges ranges;
/* Anything less than this size can't hold an archive element. */
- unsigned int min_elt;
+ unsigned int ar_hdr_size;
};
#define x_artdata(abfd) ((struct xcoff_artdata *) bfd_ardata (abfd)->tdata)
#ifndef SMALL_ARCHIVE
/* Creates big archives by default */
#define xcoff_big_format_p(abfd) \
- (bfd_ardata (abfd) != NULL \
- && (x_artdata (abfd) == NULL \
- || x_artdata (abfd)->u.hdr.magic[1] == 'b'))
+ (bfd_ardata (abfd) == NULL \
+ || x_artdata (abfd) == NULL \
+ || x_artdata (abfd)->u.hdr.magic[1] != 'a')
#else
/* Creates small archives by default. */
#define xcoff_big_format_p(abfd) \
- (bfd_ardata (abfd) != NULL \
+ (bfd_ardata (abfd) != NULL \
&& x_artdata (abfd) != NULL \
&& x_artdata (abfd)->u.hdr.magic[1] == 'b')
#endif