Bug 1270310 - Part 3: Make string assignment in HTMLInputElement::GetValueInternal fallible. r=peterv
☠☠ backed out by df9fd4cff088 ☠ ☠
authorEric Rahm <erahm@mozilla.com>
Fri, 20 May 2016 16:15:52 -0700
changeset 340136 605790e5e6118254accae9c34c5f1a98948972da
parent 340135 4c302e1119e165fd389ced209be1ed34ef9e0231
child 340137 ff9ace379d788d46677e933021ebd041bff8607d
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)
reviewerspeterv
bugs1270310
milestone49.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 1270310 - Part 3: Make string assignment in HTMLInputElement::GetValueInternal fallible. r=peterv This makes the string assignment fallible and also adds checks for the return value from GetValueInternal and GetValue.
dom/html/HTMLInputElement.cpp
dom/html/HTMLInputElement.h
dom/webidl/HTMLInputElement.webidl
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -1522,35 +1522,38 @@ HTMLInputElement::SetWidth(uint32_t aWid
   ErrorResult rv;
   SetWidth(aWidth, rv);
   return rv.StealNSResult();
 }
 
 NS_IMETHODIMP
 HTMLInputElement::GetValue(nsAString& aValue)
 {
-  GetValueInternal(aValue);
+  nsresult rv = GetValueInternal(aValue);
+  if (NS_FAILED(rv)) {
+    return rv;
+  }
 
   // Don't return non-sanitized value for types that are experimental on mobile.
   if (IsExperimentalMobileType(mType)) {
     SanitizeValue(aValue);
   }
 
   return NS_OK;
 }
 
 nsresult
 HTMLInputElement::GetValueInternal(nsAString& aValue) const
 {
   switch (GetValueMode()) {
     case VALUE_MODE_VALUE:
       if (IsSingleLineTextControl(false)) {
         mInputData.mState->GetValue(aValue, true);
-      } else {
-        aValue.Assign(mInputData.mValue);
+      } else if (!aValue.Assign(mInputData.mValue, fallible)) {
+        return NS_ERROR_OUT_OF_MEMORY;
       }
       return NS_OK;
 
     case VALUE_MODE_FILENAME:
       if (nsContentUtils::LegacyIsCallerChromeOrNativeCode()) {
 #ifndef MOZ_CHILD_PERMISSIONS
         aValue.Assign(mFirstFilePath);
 #else
@@ -1677,16 +1680,25 @@ HTMLInputElement::GetValueAsDecimal() co
 
   GetValueInternal(stringValue);
 
   return !ConvertStringToNumber(stringValue, decimalValue) ? Decimal::nan()
                                                            : decimalValue;
 }
 
 void
+HTMLInputElement::GetValue(nsAString& aValue, ErrorResult& aRv)
+{
+  nsresult rv = GetValue(aValue);
+  if (NS_FAILED(rv)) {
+    aRv.Throw(rv);
+  }
+}
+
+void
 HTMLInputElement::SetValue(const nsAString& aValue, ErrorResult& aRv)
 {
   // check security.  Note that setting the value to the empty string is always
   // OK and gives pages a way to clear a file input if necessary.
   if (mType == NS_FORM_INPUT_FILE) {
     if (!aValue.IsEmpty()) {
       if (!nsContentUtils::IsCallerChrome()) {
         // setting the value of a "FILE" input widget requires
@@ -5758,19 +5770,22 @@ HTMLInputElement::SaveState()
       if ((GetValueMode() == VALUE_MODE_DEFAULT &&
            mType != NS_FORM_INPUT_HIDDEN) ||
           mType == NS_FORM_INPUT_PASSWORD || !mValueChanged) {
         break;
       }
 
       inputState = new HTMLInputElementState();
       nsAutoString value;
-      GetValue(value);
-      nsresult rv =
-        nsLinebreakConverter::ConvertStringLineBreaks(
+      nsresult rv = GetValue(value);
+      if (NS_FAILED(rv)) {
+        return rv;
+      }
+
+      rv = nsLinebreakConverter::ConvertStringLineBreaks(
              value,
              nsLinebreakConverter::eLinebreakPlatform,
              nsLinebreakConverter::eLinebreakContent);
 
       if (NS_FAILED(rv)) {
         NS_ERROR("Converting linebreaks failed!");
         return rv;
       }
--- a/dom/html/HTMLInputElement.h
+++ b/dom/html/HTMLInputElement.h
@@ -618,17 +618,17 @@ public:
   }
 
   // XPCOM GetDefaultValue() is OK
   void SetDefaultValue(const nsAString& aValue, ErrorResult& aRv)
   {
     SetHTMLAttr(nsGkAtoms::value, aValue, aRv);
   }
 
-  // XPCOM GetValue() is OK
+  void GetValue(nsAString& aValue, ErrorResult& aRv);
   void SetValue(const nsAString& aValue, ErrorResult& aRv);
 
   Nullable<Date> GetValueAsDate(ErrorResult& aRv);
 
   void SetValueAsDate(Nullable<Date>, ErrorResult& aRv);
 
   double ValueAsNumber() const
   {
--- a/dom/webidl/HTMLInputElement.webidl
+++ b/dom/webidl/HTMLInputElement.webidl
@@ -81,17 +81,17 @@ interface HTMLInputElement : HTMLElement
   [Pure, SetterThrows]
            attribute DOMString src;
   [Pure, SetterThrows]
            attribute DOMString step;
   [Pure, SetterThrows]
            attribute DOMString type;
   [Pure, SetterThrows]
            attribute DOMString defaultValue;
-  [Pure, TreatNullAs=EmptyString, SetterThrows]
+  [Pure, TreatNullAs=EmptyString, Throws]
            attribute DOMString value;
   [Throws, Pref="dom.experimental_forms"]
            attribute Date? valueAsDate;
   [Pure, SetterThrows]
            attribute unrestricted double valueAsNumber;
            attribute unsigned long width;
 
   [Throws]