Commit: Fix buffer overflows in ld

Nick Clifton nickc@redhat.com
Tue Jan 31 12:06:00 GMT 2017


Hi Guys,

  I am applying the patch below to fix two buffer overflows in the
  linker when it is printing fixed strings.  The buffer used was big
  enough for the English text, but when translated, the string could end
  up being longer than the buffer.  The solution was simple - since the
  strings are static, no buffer is needed.

Cheers
  Nick

ld/ChangeLog
2017-01-31  Nick Clifton  <nickc@redhat.com>

	* ldmain.c (add_archive_element): Eliminate string buffer.
	* ldlang.c (lang_print_asneeded): Likewise.

diff --git a/ld/ldlang.c b/ld/ldlang.c
index dafc348..1396c5b 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -2035,14 +2035,11 @@ static void
 lang_print_asneeded (void)
 {
   struct asneeded_minfo *m;
-  char buf[100];
 
   if (asneeded_list_head == NULL)
     return;
 
-  sprintf (buf, _("\nAs-needed library included "
-		  "to satisfy reference by file (symbol)\n\n"));
-  minfo ("%s", buf);
+  minfo (_("\nAs-needed library included to satisfy reference by file (symbol)\n\n"));
 
   for (m = asneeded_list_head; m != NULL; m = m->next)
     {
diff --git a/ld/ldmain.c b/ld/ldmain.c
index 1e48b1a..e049de3 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -871,11 +871,7 @@ add_archive_element (struct bfd_link_info *info,
 
       if (!header_printed)
 	{
-	  char buf[100];
-
-	  sprintf (buf, _("Archive member included "
-			  "to satisfy reference by file (symbol)\n\n"));
-	  minfo ("%s", buf);
+	  minfo (_("Archive member included to satisfy reference by file (symbol)\n\n"));
 	  header_printed = TRUE;
 	}
 



More information about the Binutils mailing list