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 4/4] Fix references past allocated memory for i386-*-go32


Hi,

while sanity checking my changes by valgrind I got this error, in fact
unrelated to my previous patches:

Invalid read of size 1
   at 0x43CF59: bfd_getb16 (libbfd.c:553)
   by 0x5B892D: coff_swap_filehdr_in (coffswap.h:274)
   by 0x437D4F: coff_object_p (coffgen.c:265)
   by 0x43C5E4: bfd_check_format_matches (format.c:211)
   by 0x4061B2: copy_file (objcopy.c:2210)
   by 0x409687: copy_main (objcopy.c:3865)
   by 0x409968: main (objcopy.c:3961)
 Address 0x4c2b90c is 0 bytes after a block of size 20 alloc'd
   at 0x4A0763E: malloc (vg_replace_malloc.c:207)
   by 0x43CB6A: bfd_malloc (libbfd.c:173)
   by 0x437CB8: coff_object_p (coffgen.c:255)
   by 0x43C5E4: bfd_check_format_matches (format.c:211)
   by 0x4061B2: copy_file (objcopy.c:2210)
   by 0x409687: copy_main (objcopy.c:3865)
   by 0x409968: main (objcopy.c:3961)

The patched code may be somehow duplicate to this coff_swap_filehdr_in() line
but that duplicity removal is IMO for some other patch.

#ifdef TIC80_TARGET_ID
  filehdr_dst->f_target_id = H_GET_16 (abfd, filehdr_src->f_target_id);
#endif


Thanks,
Jan


include/coff/
2009-08-09  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix references past allocated memory for i386-*-go32.
	* ti.h (COFF_ADJUST_FILEHDR_IN_POST, COFF_ADJUST_FILEHDR_OUT_POST):
	Reference F_TARGET_ID only when !COFF0_P.

--- include/coff/ti.h	23 Dec 2008 10:59:56 -0000	1.19
+++ include/coff/ti.h	9 Aug 2009 10:37:55 -0000
@@ -102,19 +102,21 @@ struct external_filehdr
 #define COFF_ADJUST_FILEHDR_IN_POST(abfd, src, dst) \
   do									\
     {									\
-      ((struct internal_filehdr *)(dst))->f_target_id =			\
-	H_GET_16 (abfd, ((FILHDR *)(src))->f_target_id);		\
+      if (!COFF0_P (abfd))						\
+	((struct internal_filehdr *)(dst))->f_target_id =		\
+	  H_GET_16 (abfd, ((FILHDR *)(src))->f_target_id);		\
     }									\
   while (0)
 #endif
 
 #ifndef COFF_ADJUST_FILEHDR_OUT_POST
 #define COFF_ADJUST_FILEHDR_OUT_POST(abfd, src, dst) \
-  do									\
-    {									\
-      H_PUT_16 (abfd, ((struct internal_filehdr *)(src))->f_target_id,	\
-	       ((FILHDR *)(dst))->f_target_id);				\
-    }									\
+  do									 \
+    {									 \
+      if (!COFF0_P (abfd))						 \
+	H_PUT_16 (abfd, ((struct internal_filehdr *)(src))->f_target_id, \
+		 ((FILHDR *)(dst))->f_target_id);			 \
+    }									 \
   while (0)
 #endif
 


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