Bug 1142332 - Prevent calling CSP_EnumToKeyword with CSP_HASH. r=ckerschb
authorFrederik Braun <fbraun+gh@mozilla.com>
Sun, 24 Apr 2016 14:56:22 -0400
changeset 332594 a4845199b1bbe3391d6d2bf6925cdb368cb09345
parent 332593 c69d01fb9aaae166a5d2055bfb75f622f58adb4d
child 332595 18ff4b609573846d75245079f8e18e2a584ee89d
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb
bugs1142332
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1142332 - Prevent calling CSP_EnumToKeyword with CSP_HASH. r=ckerschb MozReview-Commit-ID: I1w9QrWJeEo
dom/security/nsCSPUtils.h
--- a/dom/security/nsCSPUtils.h
+++ b/dom/security/nsCSPUtils.h
@@ -140,17 +140,21 @@ static const char* CSPStrKeywords[] = {
 };
 
 inline const char* CSP_EnumToKeyword(enum CSPKeyword aKey)
 {
   // Make sure all elements in enum CSPKeyword got added to CSPStrKeywords.
   static_assert((sizeof(CSPStrKeywords) / sizeof(CSPStrKeywords[0]) ==
                 static_cast<uint32_t>(CSP_LAST_KEYWORD_VALUE)),
                 "CSP_LAST_KEYWORD_VALUE does not match length of CSPStrKeywords");
-  return CSPStrKeywords[static_cast<uint32_t>(aKey)];
+
+  if (static_cast<uint32_t>(aKey) < static_cast<uint32_t>(CSP_LAST_KEYWORD_VALUE)) {
+      return CSPStrKeywords[static_cast<uint32_t>(aKey)];
+  }
+  return "error: invalid keyword in CSP_EnumToKeyword";
 }
 
 inline CSPKeyword CSP_KeywordToEnum(const nsAString& aKey)
 {
   nsString lowerKey = PromiseFlatString(aKey);
   ToLowerCase(lowerKey);
 
   static_assert(CSP_LAST_KEYWORD_VALUE ==