Bug 1257765 - Limit the length of notification strings to 5000 characters. r=spohl, a=ritu
authorJosh Aas <joshmoz@fastmail.com>
Sun, 26 Jun 2016 18:51:05 -0400
changeset 341838 d219f175e1802a357e64a7b7d9159f6ef8b3afcc
parent 341837 31348bf997584cddcac6d741c1070c03f4a5ca5c
child 341839 373f762e0b839a516317478c553be0bc8c5d6d6e
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersspohl, ritu
bugs1257765
milestone49.0a2
Bug 1257765 - Limit the length of notification strings to 5000 characters. r=spohl, a=ritu
widget/cocoa/OSXNotificationCenter.mm
--- a/widget/cocoa/OSXNotificationCenter.mm
+++ b/widget/cocoa/OSXNotificationCenter.mm
@@ -17,16 +17,18 @@
 #include "nsString.h"
 #include "nsCOMPtr.h"
 #include "nsIObserver.h"
 #include "nsIContentPolicy.h"
 #include "imgRequestProxy.h"
 
 using namespace mozilla;
 
+#define MAX_NOTIFICATION_NAME_LEN 5000
+
 #if !defined(MAC_OS_X_VERSION_10_8) || (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_8)
 @protocol NSUserNotificationCenterDelegate
 @end
 static NSString * const NSUserNotificationDefaultSoundName = @"DefaultSoundName";
 enum {
   NSUserNotificationActivationTypeNone = 0,
   NSUserNotificationActivationTypeContentsClicked = 1,
   NSUserNotificationActivationTypeActionButtonClicked = 2,
@@ -339,16 +341,23 @@ OSXNotificationCenter::ShowAlertWithIcon
                                           nsCocoaUtils::ToNSString(disableButtonTitle),
                                           nsCocoaUtils::ToNSString(settingsButtonTitle)
                                           ]
                                forKey:@"_alternateActionButtonTitles"];
     }
   }
   nsAutoString name;
   rv = aAlert->GetName(name);
+  // Don't let an alert name be more than MAX_NOTIFICATION_NAME_LEN characters.
+  // More than that shouldn't be necessary and userInfo (assigned to below) has
+  // a length limit of 16k on OS X 10.11. Exception thrown if limit exceeded.
+  if (name.Length() > MAX_NOTIFICATION_NAME_LEN) {
+    return NS_ERROR_FAILURE;
+  }
+
   NS_ENSURE_SUCCESS(rv, rv);
   NSString *alertName = nsCocoaUtils::ToNSString(name);
   if (!alertName) {
     return NS_ERROR_FAILURE;
   }
   notification.userInfo = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:alertName, nil]
                                                       forKeys:[NSArray arrayWithObjects:@"name", nil]];