Fix GCC 8's -Wstringop-overflow on bfd/coff-rs6000.c
authorSergio Durigan Junior <sergiodj@redhat.com>
Tue, 6 Feb 2018 15:37:04 +0000 (10:37 -0500)
committerSergio Durigan Junior <sergiodj@redhat.com>
Tue, 6 Feb 2018 16:47:24 +0000 (11:47 -0500)
GCC 8 will bring a new warning option which will detect possible
overflow and truncation on string manipulation functions.  For more
details, see:

  https://gcc.gnu.org/ml/gcc-patches/2017-08/msg00471.html

While compiling BFD with it, I can see one place on bfd/coff-rs6000.c
where the warning is triggered.  This:

  (void) strncpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG);

will not include the trailing NUL on fhdr.magic, but that's fine
because it's a magic number.  The fix is trivial: just use memcpy
instead.

OK to push?

2018-02-06  Sergio Durigan Junior  <sergiodj@redhat.com>

* coff-rs6000.c (xcoff_write_archive_contents_old): Use
'memcpy' instead of 'strncpy' when writing the magic number.

bfd/ChangeLog
bfd/coff-rs6000.c

index 584f087ce8a8dc49f3e57e203163c910975e8a6e..14ed147db2ccaa587142092937e4cd6adf2e01a2 100644 (file)
@@ -1,3 +1,8 @@
+2018-02-06  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+       * coff-rs6000.c (xcoff_write_archive_contents_old): Use
+       'memcpy' instead of 'strncpy' when writing the magic number.
+
 2018-02-06  Nick Clifton  <nickc@redhat.com>
 
        PR 22794
index 2fc1feb1c5b3ca135c9975b250952402d7a2ceff..d02835ede69b22f5548a540dd48e0e19162c250d 100644 (file)
@@ -2090,7 +2090,7 @@ xcoff_write_archive_contents_old (bfd *abfd)
   char decbuf[XCOFFARMAG_ELEMENT_SIZE + 1];
 
   memset (&fhdr, 0, sizeof fhdr);
-  (void) strncpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG);
+  (void) memcpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG);
   sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR);
   sprintf (fhdr.freeoff, "%d", 0);
 
This page took 0.026556 seconds and 4 git commands to generate.