You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by gs...@apache.org on 2007/04/06 23:20:25 UTC

svn commit: r526288 - in /harmony/enhanced/drlvm/trunk/vm/vmcore/src: class_support/classloader.cpp util/jarfile_support.cpp

Author: gshimansky
Date: Fri Apr  6 14:20:24 2007
New Revision: 526288

URL: http://svn.apache.org/viewvc?view=rev&rev=526288
Log:
Applied HARMONY-3547 [drlvm] segfault on classloading due to use of alloca blowing the stack


Modified:
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/jarfile_support.cpp

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp?view=diff&rev=526288&r1=526287&r2=526288
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp Fri Apr  6 14:20:24 2007
@@ -1677,7 +1677,8 @@
 
     // read file in buf
     size_t buf_len = (size_t)finfo.size;
-    unsigned char* buf = (unsigned char*)STD_ALLOCA(buf_len);
+    unsigned char* buf = (unsigned char*)STD_MALLOC(buf_len);
+    // FIXME: check that memory was allocated
     apr_file_read(file_handle, buf, &buf_len);
 
     // close file
@@ -1685,10 +1686,11 @@
 
     // define class
     Class* clss = DefineClass(m_env, class_name->bytes, buf, 0,
-        (unsigned)buf_len); 
+        (unsigned)buf_len);
     if(clss) {
         clss->set_class_file_name(m_env->string_pool.lookup(full_name));
     }
+    STD_FREE(buf);
     apr_pool_destroy(local_pool);
 
     return clss;
@@ -1710,11 +1712,13 @@
 
     // unpack entry
     unsigned size = entry->GetContentSize();
-    unsigned char *buffer = (unsigned char *)STD_ALLOCA(size);
+    unsigned char* buffer = (unsigned char*)STD_MALLOC(size);
+    // FIXME: check that memory was allocated
 
     if(!entry->GetContent(buffer, jar_file)) {
         // cannot unpack entry
         *not_found = true;
+        STD_FREE(buffer);
         return NULL;
     }
 
@@ -1727,6 +1731,8 @@
         // set class file name
         clss->set_class_file_name(m_env->string_pool.lookup(jar_file->GetName()));
     }
+
+    STD_FREE(buffer);
 
     return clss;
 } // BootstrapClassLoader::LoadFromJarFile

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/jarfile_support.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/jarfile_support.cpp?view=diff&rev=526288&r1=526287&r2=526288
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/jarfile_support.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/jarfile_support.cpp Fri Apr  6 14:20:24 2007
@@ -91,9 +91,12 @@
         return false;
 #else // _IPF
         {
-            unsigned char* data = (unsigned char *)STD_ALLOCA(m_sizeCompressed + 1);
-            if( read( inFile, data, m_sizeCompressed ) < m_sizeCompressed )
+            unsigned char* data = (unsigned char*)STD_MALLOC(m_sizeCompressed + 1);
+            // FIXME: check that memory was allocated
+            if( read( inFile, data, m_sizeCompressed ) < m_sizeCompressed ) {
+                STD_FREE(data);
                 return false;
+            }
 
             z_stream inf;
             memset( &inf, 0, sizeof(z_stream) );
@@ -103,15 +106,20 @@
             // Using -MAX_WBITS (actually any integer less than zero)
             // disables zlib to expect specific header
             infRes = inflateInit2( &inf, -MAX_WBITS );
-            if( infRes != Z_OK )
+            if( infRes != Z_OK ) {
+                STD_FREE(data);
                 return false;
+            }
 
             inf.next_in = data;
             inf.avail_in = m_sizeCompressed;
             //inf.data_type = (m_fileEntry.m_internalAttrs&JAR_FILE_TEXT)?Z_ASCII:Z_BINARY;
             inf.data_type = Z_BINARY;
             infRes = inflate( &inf, Z_FINISH );
-            if( infRes != Z_STREAM_END ) break;
+            STD_FREE(data);
+            if( infRes != Z_STREAM_END ) {
+                break;
+            }
             infRes = inflateEnd( &inf );
         }
 #endif //_IPF