This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[BC] Patch: FYI: fix name length computation


I'm checking this in on the BC branch.

Some code in compute_class_name was using strlen() on the result of
ZIPDIR_FILENAME.  This is not valid; this is not guaranteed to be
\0-terminated.  This caused a crash elsewhere in the compiler while
compiling a jar from Eclipse 3.

Fixed as appended.  The length of the ZIPDIR_FILENAME is in the
filename_length field of the zip entry.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* jcf-parse.c (compute_class_name): Use filename length from zip
	directory, not strlen.

Index: jcf-parse.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf-parse.c,v
retrieving revision 1.158.4.9
diff -u -r1.158.4.9 jcf-parse.c
--- jcf-parse.c 29 Oct 2004 09:18:39 -0000 1.158.4.9
+++ jcf-parse.c 3 Nov 2004 00:07:10 -0000
@@ -1302,13 +1303,15 @@
   char *class_name_in_zip_dir = ZIPDIR_FILENAME (zdir);
   char *class_name;
   int i;
-  int filename_length;
+  int filename_length = zdir->filename_length;
 
-  while (strncmp (class_name_in_zip_dir, "./", 2) == 0)
-    class_name_in_zip_dir += 2;
+  while (filename_length > 2 && strncmp (class_name_in_zip_dir, "./", 2) == 0)
+    {
+      class_name_in_zip_dir += 2;
+      filename_length -= 2;
+    }
 
-  filename_length = (strlen (class_name_in_zip_dir)
-		     - strlen (".class"));
+  filename_length -= strlen (".class");
   class_name = ALLOC (filename_length + 1);
   memcpy (class_name, class_name_in_zip_dir, filename_length);
   class_name [filename_length] = '\0';


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