Bug 1439632 - Make sure password is always empty after calling SetPassword(EmptyCString()) on a URI draft
authorValentin Gosu <valentin.gosu@gmail.com>
Sat, 14 Apr 2018 00:10:40 +0200
changeset 781954 02352e7942596d99b18acdf9aa4cd7a7ecf38d79
parent 781727 8a94faa5cc60495da5d80d4b3c07bf5877d2e6d8
push id106457
push uservalentin.gosu@gmail.com
push dateFri, 13 Apr 2018 22:11:31 +0000
bugs1439632
milestone61.0a1
Bug 1439632 - Make sure password is always empty after calling SetPassword(EmptyCString()) on a URI MozReview-Commit-ID: LaHHo3A2xvk
netwerk/base/nsStandardURL.cpp
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -1784,16 +1784,24 @@ nsStandardURL::SetUsername(const nsACStr
 
 nsresult
 nsStandardURL::SetPassword(const nsACString &input)
 {
     ENSURE_MUTABLE();
 
     const nsPromiseFlatCString &password = PromiseFlatCString(input);
 
+    auto clearedPassword = MakeScopeExit([&password, this]() {
+        // Check that if this method is called with the empty string then the
+        // password is definitely cleared when exiting this method.
+        if (password.IsEmpty()) {
+            MOZ_DIAGNOSTIC_ASSERT(this->Password().IsEmpty());
+        }
+    });
+
     LOG(("nsStandardURL::SetPassword [password=%s]\n", password.get()));
 
     if (mURLType == URLTYPE_NO_AUTHORITY) {
         if (password.IsEmpty())
             return NS_OK;
         NS_WARNING("cannot set password on no-auth url");
         return NS_ERROR_UNEXPECTED;
     }