Bug 1384153 - Artifact and local builds crashing content tabs on latest autoland to m-c merge. r=spohl draft
authorHaik Aftandilian <haftandilian@mozilla.com>
Wed, 26 Jul 2017 22:47:10 -0700
changeset 617044 b74fd0f4cece68bbf3f251c533d7b239cbc7e7ee
parent 616724 658cba6a971257e2ba39715ec938256dfc414776
child 639672 1834201ebcb8a225f4c3953eb387e940844d60b7
push id70897
push userhaftandilian@mozilla.com
push dateThu, 27 Jul 2017 19:27:06 +0000
reviewersspohl
bugs1384153
milestone56.0a1
Bug 1384153 - Artifact and local builds crashing content tabs on latest autoland to m-c merge. r=spohl MozReview-Commit-ID: 6xHFTCXVgr7
security/sandbox/common/SandboxSettings.cpp
--- a/security/sandbox/common/SandboxSettings.cpp
+++ b/security/sandbox/common/SandboxSettings.cpp
@@ -35,34 +35,67 @@ bool IsDevelopmentBuild()
 /*
  * Helper function to read a string value for a given key from the .app's
  * Info.plist.
  */
 static nsresult
 GetStringValueFromBundlePlist(const nsAString& aKey, nsAutoCString& aValue)
 {
   CFBundleRef mainBundle = CFBundleGetMainBundle();
+  if (mainBundle == nullptr) {
+    return NS_ERROR_FAILURE;
+  }
 
   // Read this app's bundle Info.plist as a dictionary
   CFDictionaryRef bundleInfoDict = CFBundleGetInfoDictionary(mainBundle);
-  if (bundleInfoDict == NULL) {
+  if (bundleInfoDict == nullptr) {
     return NS_ERROR_FAILURE;
   }
 
   nsAutoCString keyAutoCString = NS_ConvertUTF16toUTF8(aKey);
   CFStringRef key = CFStringCreateWithCString(kCFAllocatorDefault,
                                               keyAutoCString.get(),
                                               kCFStringEncodingUTF8);
+  if (key == nullptr) {
+    return NS_ERROR_FAILURE;
+  }
 
   CFStringRef value = (CFStringRef)CFDictionaryGetValue(bundleInfoDict, key);
+  CFRelease(key);
+  if (value == nullptr) {
+    return NS_ERROR_FAILURE;
+  }
+
+  CFIndex valueLength = CFStringGetLength(value);
+  if (valueLength == 0) {
+    return NS_ERROR_FAILURE;
+  }
+
   const char* valueCString = CFStringGetCStringPtr(value,
                                                    kCFStringEncodingUTF8);
-  aValue.Assign(valueCString);
-  CFRelease(key);
+  if (valueCString) {
+    aValue.Assign(valueCString);
+    return NS_OK;
+  }
 
+  CFIndex maxLength =
+    CFStringGetMaximumSizeForEncoding(valueLength, kCFStringEncodingUTF8) + 1;
+  char* valueBuffer = static_cast<char*>(moz_xmalloc(maxLength));
+  if (!valueBuffer) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
+
+  if (!CFStringGetCString(value, valueBuffer, maxLength,
+                          kCFStringEncodingUTF8)) {
+    free(valueBuffer);
+    return NS_ERROR_FAILURE;
+  }
+
+  aValue.Assign(valueBuffer);
+  free(valueBuffer);
   return NS_OK;
 }
 
 /*
  * Helper function for reading a path string from the .app's Info.plist
  * and returning a directory object for that path with symlinks resolved.
  */
 static nsresult