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

[patch RFC] Fix PR binutils/2584


Hi,

The attached patch is to fix PR binutils/2584:

http://sourceware.org/bugzilla/show_bug.cgi?id=2584

It seems that bfd/tekhex.c:getsym() causes that as described in
the trail #2 of the PR.  The patch attached seems to fix the given
test case in PR and is regtested on i686-pc-linux-gnu with no new
failures, though it'd be better to add more checks.

Regards,
	kaz
--
2006-04-26  Kaz Kojima  <kkojima@rr.iij4u.or.jp>

	PR 2584
	* tekhex.c (first_phase): Change return type to bfd_boolean
	and return false if the unexpected character is found.
	(pass_over): Change return type to bfd_boolean and the type of
	the second argument to bfd_boolean (*) (bfd *, int, char *).
	Return false if FUNC returns false.
	(tekhex_object_p): Return NULL if pass_over fails.


diff -uprN ORIG/src/bfd/tekhex.c LOCAL/src/bfd/tekhex.c
--- ORIG/src/bfd/tekhex.c	2005-05-24 02:44:55.000000000 +0900
+++ LOCAL/src/bfd/tekhex.c	2006-04-22 11:24:05.000000000 +0900
@@ -333,7 +333,7 @@ insert_byte (bfd *abfd, int value, bfd_v
 /* The first pass is to find the names of all the sections, and see
   how big the data is.  */
 
-static void
+static bfd_boolean
 first_phase (bfd *abfd, int type, char *src)
 {
   asection *section = bfd_abs_section_ptr;
@@ -355,9 +355,12 @@ first_phase (bfd *abfd, int type, char *
 	  }
       }
 
-      return;
+      return TRUE;
     case '3':
       /* Symbol record, read the segment.  */
+      if (!ISHEX (*src))
+	return FALSE;
+
       len = getsym (sym, &src);
       section = bfd_get_section_by_name (abfd, sym);
       if (section == NULL)
@@ -400,6 +403,9 @@ first_phase (bfd *abfd, int type, char *
 		abfd->flags |= HAS_SYMS;
 		new->prev = abfd->tdata.tekhex_data->symbols;
 		abfd->tdata.tekhex_data->symbols = new;
+		if (!ISHEX (*src))
+		  return FALSE;
+
 		len = getsym (sym, &src);
 		new->symbol.name = bfd_alloc (abfd, (bfd_size_type) len + 1);
 		if (!new->symbol.name)
@@ -412,16 +418,20 @@ first_phase (bfd *abfd, int type, char *
 		  new->symbol.flags = BSF_LOCAL;
 		new->symbol.value = getvalue (&src) - section->vma;
 	      }
+	    default:
+	      return FALSE;
 	    }
 	}
     }
+
+  return TRUE;
 }
 
 /* Pass over a tekhex, calling one of the above functions on each
    record.  */
 
-static void
-pass_over (bfd *abfd, void (*func) (bfd *, int, char *))
+static bfd_boolean
+pass_over (bfd *abfd, bfd_boolean (*func) (bfd *, int, char *))
 {
   unsigned int chars_on_line;
   bfd_boolean eof = FALSE;
@@ -462,8 +472,11 @@ pass_over (bfd *abfd, void (*func) (bfd 
       /* Put a null at the end.  */
       src[chars_on_line] = 0;
 
-      func (abfd, type, src);
+      if (!func (abfd, type, src))
+	return FALSE;
     }
+
+  return TRUE;
 }
 
 static long
@@ -524,7 +537,9 @@ tekhex_object_p (bfd *abfd)
 
   tekhex_mkobject (abfd);
 
-  pass_over (abfd, first_phase);
+  if (!pass_over (abfd, first_phase))
+    return NULL;
+
   return abfd->xvec;
 }
 


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