Bug 1142332 - prevent calling CSP_EnumToKeyword with CSP_HASH r?ckerschb draft
authorFrederik Braun <fbraun+gh@mozilla.com>
Thu, 21 Apr 2016 12:20:46 +0200
changeset 354585 3466941c0df3032e5efd9dd91209fbfa6c8dc3f5
parent 354226 f05a1242fb29023bd7ebc492897ed3d6907733c7
child 519050 e48a13f2dc6980104c2e09510dd4f18421fcabec
push id16131
push userbmo:fbraun@mozilla.com
push dateThu, 21 Apr 2016 10:21:11 +0000
reviewersckerschb
bugs1142332
milestone48.0a1
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,16 +140,20 @@ 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");
+
+  if (static_cast<int>(aKey) >= static_cast<int>(CSP_LAST_KEYWORD_VALUE)) {
+    return "index out of bounds error";
+  }
   return CSPStrKeywords[static_cast<uint32_t>(aKey)];
 }
 
 inline CSPKeyword CSP_KeywordToEnum(const nsAString& aKey)
 {
   nsString lowerKey = PromiseFlatString(aKey);
   ToLowerCase(lowerKey);