Bug 1190777 - Add null checks to prevent bad dereferences. r=kamidphish
authorKyle <kfung@mozilla.com>
Tue, 11 Aug 2015 10:17:16 -0400
changeset 258971 7630d1aab4971744e92b5eca234fa5c864ff964c
parent 258941 4ccdd06e51d7209ba429196df7cab97bf66962db
child 258972 d9ac2969f3bb3fbd14d56a32c05bdf853b92ec9b
push id29268
push userryanvm@gmail.com
push dateTue, 25 Aug 2015 00:37:23 +0000
treeherdermozilla-central@08015770c9d6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskamidphish
bugs1190777
milestone43.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 1190777 - Add null checks to prevent bad dereferences. r=kamidphish
dom/canvas/WebGLShaderValidator.cpp
--- a/dom/canvas/WebGLShaderValidator.cpp
+++ b/dom/canvas/WebGLShaderValidator.cpp
@@ -204,59 +204,75 @@ static bool
 StartsWith(const std::string& haystack, const char (&needle)[N])
 {
     return haystack.compare(0, N - 1, needle) == 0;
 }
 
 bool
 ShaderValidator::CanLinkTo(const ShaderValidator* prev, nsCString* const out_log) const
 {
+    if (!prev) {
+        nsPrintfCString error("Passed in NULL prev ShaderValidator.");
+        *out_log = error;
+        return false;
+    }
+
     {
-        const std::vector<sh::Uniform>& vertList = *ShGetUniforms(prev->mHandle);
-        const std::vector<sh::Uniform>& fragList = *ShGetUniforms(mHandle);
+        const std::vector<sh::Uniform>* vertPtr = ShGetUniforms(prev->mHandle);
+        const std::vector<sh::Uniform>* fragPtr = ShGetUniforms(mHandle);
+        if (!vertPtr || !fragPtr) {
+            nsPrintfCString error("Could not create uniform list.");
+            *out_log = error;
+            return false;
+        }
 
-        for (auto itrFrag = fragList.begin(); itrFrag != fragList.end(); ++itrFrag) {
-            for (auto itrVert = vertList.begin(); itrVert != vertList.end(); ++itrVert) {
+        for (auto itrFrag = fragPtr->begin(); itrFrag != fragPtr->end(); ++itrFrag) {
+            for (auto itrVert = vertPtr->begin(); itrVert != vertPtr->end(); ++itrVert) {
                 if (itrVert->name != itrFrag->name)
                     continue;
 
                 if (!itrVert->isSameUniformAtLinkTime(*itrFrag)) {
                     nsPrintfCString error("Uniform `%s`is not linkable between"
                                           " attached shaders.",
                                           itrFrag->name.c_str());
                     *out_log = error;
                     return false;
                 }
 
                 break;
             }
         }
     }
     {
-        const std::vector<sh::Varying>& vertList = *ShGetVaryings(prev->mHandle);
-        const std::vector<sh::Varying>& fragList = *ShGetVaryings(mHandle);
+        const std::vector<sh::Varying>* vertPtr = ShGetVaryings(prev->mHandle);
+        const std::vector<sh::Varying>* fragPtr = ShGetVaryings(mHandle);
+        if (!vertPtr || !fragPtr) {
+            nsPrintfCString error("Could not create varying list.");
+            *out_log = error;
+            return false;
+        }
 
         nsTArray<ShVariableInfo> staticUseVaryingList;
 
-        for (auto itrFrag = fragList.begin(); itrFrag != fragList.end(); ++itrFrag) {
+        for (auto itrFrag = fragPtr->begin(); itrFrag != fragPtr->end(); ++itrFrag) {
             const ShVariableInfo varInfo = { itrFrag->type,
                                              (int)itrFrag->elementCount() };
 
             static const char prefix[] = "gl_";
             if (StartsWith(itrFrag->name, prefix)) {
                 if (itrFrag->staticUse)
                     staticUseVaryingList.AppendElement(varInfo);
 
                 continue;
             }
 
             bool definedInVertShader = false;
             bool staticVertUse = false;
 
-            for (auto itrVert = vertList.begin(); itrVert != vertList.end(); ++itrVert) {
+            for (auto itrVert = vertPtr->begin(); itrVert != vertPtr->end(); ++itrVert) {
                 if (itrVert->name != itrFrag->name)
                     continue;
 
                 if (!itrVert->isSameVaryingAtLinkTime(*itrFrag)) {
                     nsPrintfCString error("Varying `%s`is not linkable between"
                                           " attached shaders.",
                                           itrFrag->name.c_str());
                     *out_log = error;