Bug 810478 - Fix missing null termination of buffer that's used via str* functions later on. r=glandium, a=lsblakk
authorVladimir Vukicevic <vladimir@pobox.com>
Tue, 13 Nov 2012 14:21:08 -0500
changeset 114229 6e9990f737b40851ab5b4f409b77073d41e7a78a
parent 114228 0013abadb6e483955d555f8d7e16db5ed2811629
child 114230 2636c23bd0234eeb6815dfa37a703930b40062aa
push id2691
push userryanvm@gmail.com
push dateThu, 15 Nov 2012 03:10:29 +0000
treeherdermozilla-aurora@0cecfe1dde64 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium, lsblakk
bugs810478
milestone18.0a2
Bug 810478 - Fix missing null termination of buffer that's used via str* functions later on. r=glandium, a=lsblakk
mozglue/android/APKOpen.cpp
--- a/mozglue/android/APKOpen.cpp
+++ b/mozglue/android/APKOpen.cpp
@@ -637,26 +637,30 @@ static void * mozload(const char * path,
 #ifdef MOZ_CRASHREPORTER
 static void *
 extractBuf(const char * path, Zip *zip)
 {
   Zip::Stream s;
   if (!zip->GetStream(path, &s))
     return NULL;
 
-  void * buf = malloc(s.GetUncompressedSize());
+  // allocate space for a trailing null byte
+  void * buf = malloc(s.GetUncompressedSize() + 1);
   if (buf == (void *)-1) {
     __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't alloc decompression buffer for %s", path);
     return NULL;
   }
   if (s.GetType() == Zip::Stream::DEFLATE)
     extractLib(s, buf);
   else
     memcpy(buf, s.GetBuffer(), s.GetUncompressedSize());
 
+  // null terminate it
+  ((unsigned char*) buf)[s.GetUncompressedSize()] = 0;
+
   return buf;
 }
 #endif
 
 static int mapping_count = 0;
 static char *file_ids = NULL;
 
 #define MAX_MAPPING_INFO 32