Bug 1404224 - Fix ubsan runtime error for nsCSSTokenSerializationType. r=heycam
authorArthur Edelstein <arthuredelstein@gmail.com>
Tue, 03 Oct 2017 10:06:00 -0400
changeset 1311808 30a40b41d5902fe1cc81c0f0d9e6ece7255b52d0
parent 1311807 0c8579323603a00386b3e8e1d188f3e5cb42ffa4
child 1311809 95f2051829f1d920607c1958bd0631af35e69780
push id225897
push useropettay@mozilla.com
push dateWed, 04 Oct 2017 19:25:01 +0000
treeherdertry@2f2f41234c44 [default view] [failures only]
reviewersheycam
bugs1404224
milestone58.0a1
Bug 1404224 - Fix ubsan runtime error for nsCSSTokenSerializationType. r=heycam
layout/style/CSSVariableResolver.cpp
--- a/layout/style/CSSVariableResolver.cpp
+++ b/layout/style/CSSVariableResolver.cpp
@@ -144,22 +144,24 @@ CSSVariableResolver::ResolveVariable(siz
     for (size_t i = 0, n = mReferences[aID].Length(); i < n; i++) {
       size_t j = mReferences[aID][i];
       if (aID != j && !mVariables[j].mResolved) {
         ResolveVariable(j);
       }
     }
     nsString resolvedValue;
     nsCSSTokenSerializationType firstToken, lastToken;
-    if (!mParser.ResolveVariableValue(mVariables[aID].mValue, mOutput,
-                                      resolvedValue, firstToken, lastToken)) {
-      resolvedValue.Truncate(0);
+    if (mParser.ResolveVariableValue(mVariables[aID].mValue, mOutput,
+                                     resolvedValue, firstToken, lastToken)) {
+      mOutput->Put(mVariables[aID].mVariableName, resolvedValue,
+                   firstToken, lastToken);
+    } else {
+      mOutput->Put(mVariables[aID].mVariableName, EmptyString(),
+                   eCSSTokenSerialization_Nothing, eCSSTokenSerialization_Nothing);
     }
-    mOutput->Put(mVariables[aID].mVariableName, resolvedValue,
-                 firstToken, lastToken);
   }
   mVariables[aID].mResolved = true;
 }
 
 void
 CSSVariableResolver::Resolve(const CSSVariableValues* aInherited,
                              const CSSVariableDeclarations* aSpecified)
 {