This is the mail archive of the binutils-cvs@sourceware.org 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]

[binutils-gdb] Check asprintf return value


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=34d75fb5c419a23922174c520e124523e01114c4

commit 34d75fb5c419a23922174c520e124523e01114c4
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Feb 20 18:54:41 2019 +1030

    Check asprintf return value
    
    git a31b8bd9a05 introduced a warning (depending on your system
    headers).
    
    	PR 24225
    	* elf32-nios2.c (nios2_elf32_relocate_section): Check asprintf
    	return value.

Diff:
---
 bfd/ChangeLog     |  6 ++++++
 bfd/elf32-nios2.c | 11 +++++++----
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index bb73a97..8183678 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2019-02-20  Alan Modra  <amodra@gmail.com>
+
+	PR 24225
+	* elf32-nios2.c (nios2_elf32_relocate_section): Check asprintf
+	return value.
+
 2019-02-20  Michael Roitzsch  <reactorcontrol@icloud.com>
 
 	* configure.ac (SHARED_LIBADD): Add -liberty -lintl for all
diff --git a/bfd/elf32-nios2.c b/bfd/elf32-nios2.c
index b0f200d..5d787eb 100644
--- a/bfd/elf32-nios2.c
+++ b/bfd/elf32-nios2.c
@@ -3821,7 +3821,9 @@ nios2_elf32_relocate_section (bfd *output_bfd,
 
 		  format = _("global pointer relative relocation at address "
 			     "%#" PRIx64 " when _gp not defined\n");
-		  asprintf (&msgbuf, format, (uint64_t) reloc_address);
+		  if (asprintf (&msgbuf, format,
+				(uint64_t) reloc_address) == -1)
+		    msgbuf = NULL;
 		  msg = msgbuf;
 		  r = bfd_reloc_dangerous;
 		}
@@ -3851,9 +3853,10 @@ nios2_elf32_relocate_section (bfd *output_bfd,
 				 "the global pointer (at %#" PRIx64 ") "
 				 "because the offset (%" PRId64 ") is out of "
 				 "the allowed range, -32678 to 32767\n" );
-		      asprintf (&msgbuf, format, name,
-				(uint64_t) symbol_address, (uint64_t) gp,
-				(int64_t) relocation);
+		      if (asprintf (&msgbuf, format, name,
+				    (uint64_t) symbol_address, (uint64_t) gp,
+				    (int64_t) relocation) == -1)
+			msgbuf = NULL;
 		      msg = msgbuf;
 		      r = bfd_reloc_outofrange;
 		    }


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