Pārlūkot izejas kodu

HADOOP-458. Fix a memory-corruption in libhdfs. Contributed by Owen.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@441587 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 18 gadi atpakaļ
vecāks
revīzija
3d864eeb77
2 mainītis faili ar 9 papildinājumiem un 2 dzēšanām
  1. 3 0
      CHANGES.txt
  2. 6 2
      src/c++/libhdfs/hdfs.c

+ 3 - 0
CHANGES.txt

@@ -155,6 +155,9 @@ Trunk (unreleased changes)
 38. HADOOP-483. Improvements to libhdfs build and documentation.
     (Arun C Murthy via cutting)
 
+39. HADOOP-458.  Fix a memory corruption bug in libhdfs.
+    (omalley via cutting)
+
 
 Release 0.5.0 - 2006-08-04
 

+ 6 - 2
src/c++/libhdfs/hdfs.c

@@ -94,8 +94,12 @@ static inline JNIEnv* getJNIEnv()
         		fprintf(stderr, "Please set the environment variable $CLASSPATH!\n");
         		exit(-1);
         } 
-        char *optHadoopClassPath = malloc(sizeof(char) * strlen(hadoopClassPath) + 16);
-        sprintf(optHadoopClassPath, "-Djava.class.path=%s", hadoopClassPath);
+        char *hadoopClassPathVMArg = "-Djava.class.path=";
+        size_t optHadoopClassPathLen = strlen(hadoopClassPath) + 
+        								strlen(hadoopClassPathVMArg) + 1;
+        char *optHadoopClassPath = malloc(sizeof(char) * optHadoopClassPathLen);
+        snprintf(optHadoopClassPath, optHadoopClassPathLen,
+        	"%s%s", hadoopClassPathVMArg, hadoopClassPath);
 
         //Create the VM
         JavaVMInitArgs vm_args;