Bug 1384153 - Artifact and local builds crashing content tabs on latest autoland to m-c merge. r=spohl
MozReview-Commit-ID: 6xHFTCXVgr7
--- 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