This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] fix ar/ranlib regression with ar_fmag clobberation

This change:

	2012-05-16  Alan Modra  <>

		* 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?


2012-05-17  Roland McGrath  <>

	* 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;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]