This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] fix ar/ranlib regression with ar_fmag clobberation
- From: Roland McGrath <mcgrathr at google dot com>
- To: Alan Modra <amodra at gmail dot com>
- Cc: binutils at sourceware dot org
- Date: Thu, 17 May 2012 13:45:37 -0700
- Subject: [PATCH] fix ar/ranlib regression with ar_fmag clobberation
This change:
2012-05-16 Alan Modra <amodra@gmail.com>
* archive.c (_bfd_generic_read_ar_hdr_mag): Ensure sscanf
stops at end of ar_size field.
results in clobbering the stored ar_fmag field. Among other things,
this makes ranlib produce a malformed archive.
A simple fix is below.
Ok for trunk?
Thanks,
Roland
bfd/
2012-05-17 Roland McGrath <mcgrathr@google.com>
* archive.c (_bfd_generic_read_ar_hdr_mag): Fix last change so as
not to clobber the ar_fmag field stored in ARED->arch_header.
diff --git a/bfd/archive.c b/bfd/archive.c
index eb5f5ec..26547ba 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -455,6 +455,8 @@ _bfd_generic_read_ar_hdr_mag (bfd *abfd, const char *mag)
char *allocptr = 0;
file_ptr origin = 0;
unsigned int extra_size = 0;
+ char fmag_save;
+ int scan;
if (bfd_bread (hdrp, sizeof (struct ar_hdr), abfd) != sizeof (struct ar_hdr))
{
@@ -471,8 +473,11 @@ _bfd_generic_read_ar_hdr_mag (bfd *abfd, const char *mag)
}
errno = 0;
+ fmag_save = hdr.ar_fmag[0];
hdr.ar_fmag[0] = 0;
- if (sscanf (hdr.ar_size, "%" BFD_VMA_FMT "u", &parsed_size) != 1)
+ scan = sscanf (hdr.ar_size, "%" BFD_VMA_FMT "u", &parsed_size);
+ hdr.ar_fmag[0] = fmag_save;
+ if (scan != 1)
{
bfd_set_error (bfd_error_malformed_archive);
return NULL;