Bug 1251801 - Ensure arguments of all public methods are checked. r=keeler
authorCykesiopka <cykesiopka.bmo@gmail.com>
Tue, 29 Mar 2016 18:14:29 -0700
changeset 291035 8dea713c9fcde4a2b19492cb096043240935028f
parent 291034 667fa766321fe60527c8888b350268ae117612cd
child 291036 202e3131cadb2a43e14f9f6438834d972686a5b5
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskeeler
bugs1251801
milestone48.0a1
Bug 1251801 - Ensure arguments of all public methods are checked. r=keeler MozReview-Commit-ID: 1UQ4thOmUGb
security/manager/ssl/nsPK11TokenDB.cpp
--- a/security/manager/ssl/nsPK11TokenDB.cpp
+++ b/security/manager/ssl/nsPK11TokenDB.cpp
@@ -14,19 +14,21 @@
 #include "prerror.h"
 #include "ScopedNSSTypes.h"
 #include "secerr.h"
 
 extern mozilla::LazyLogModule gPIPNSSLog;
 
 NS_IMPL_ISUPPORTS(nsPK11Token, nsIPK11Token)
 
-nsPK11Token::nsPK11Token(PK11SlotInfo *slot)
+nsPK11Token::nsPK11Token(PK11SlotInfo* slot)
   : mUIContext(new PipUIContext())
 {
+  MOZ_ASSERT(slot);
+
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown())
     return;
 
   mSlot.reset(PK11_ReferenceSlot(slot));
   mSeries = PK11_GetSlotSeries(slot);
 
   Unused << refreshTokenInfo(locker);
@@ -85,28 +87,33 @@ nsPK11Token::~nsPK11Token()
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown()) {
     return;
   }
   destructorSafeDestroyNSSReference();
   shutdown(calledFromObject);
 }
 
-void nsPK11Token::virtualDestroyNSSReference()
+void
+nsPK11Token::virtualDestroyNSSReference()
 {
   destructorSafeDestroyNSSReference();
 }
 
-void nsPK11Token::destructorSafeDestroyNSSReference()
+void
+nsPK11Token::destructorSafeDestroyNSSReference()
 {
   mSlot = nullptr;
 }
 
-NS_IMETHODIMP nsPK11Token::GetTokenName(char16_t * *aTokenName)
+NS_IMETHODIMP
+nsPK11Token::GetTokenName(char16_t** aTokenName)
 {
+  NS_ENSURE_ARG_POINTER(aTokenName);
+
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown()) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   // handle removals/insertions
   if (PK11_GetSlotSeries(mSlot.get()) != mSeries) {
     nsresult rv = refreshTokenInfo(locker);
@@ -115,18 +122,21 @@ NS_IMETHODIMP nsPK11Token::GetTokenName(
     }
   }
   *aTokenName = ToNewUnicode(mTokenName);
   if (!*aTokenName) return NS_ERROR_OUT_OF_MEMORY;
 
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPK11Token::GetTokenLabel(char16_t **aTokLabel)
+NS_IMETHODIMP
+nsPK11Token::GetTokenLabel(char16_t** aTokLabel)
 {
+  NS_ENSURE_ARG_POINTER(aTokLabel);
+
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown()) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   // handle removals/insertions
   if (PK11_GetSlotSeries(mSlot.get()) != mSeries) {
     nsresult rv = refreshTokenInfo(locker);
@@ -134,18 +144,21 @@ NS_IMETHODIMP nsPK11Token::GetTokenLabel
       return rv;
     }
   }
   *aTokLabel = ToNewUnicode(mTokenLabel);
   if (!*aTokLabel) return NS_ERROR_OUT_OF_MEMORY;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPK11Token::GetTokenManID(char16_t **aTokManID)
+NS_IMETHODIMP
+nsPK11Token::GetTokenManID(char16_t** aTokManID)
 {
+  NS_ENSURE_ARG_POINTER(aTokManID);
+
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown()) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   // handle removals/insertions
   if (PK11_GetSlotSeries(mSlot.get()) != mSeries) {
     nsresult rv = refreshTokenInfo(locker);
@@ -153,18 +166,21 @@ NS_IMETHODIMP nsPK11Token::GetTokenManID
       return rv;
     }
   }
   *aTokManID = ToNewUnicode(mTokenManID);
   if (!*aTokManID) return NS_ERROR_OUT_OF_MEMORY;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPK11Token::GetTokenHWVersion(char16_t **aTokHWVersion)
+NS_IMETHODIMP
+nsPK11Token::GetTokenHWVersion(char16_t** aTokHWVersion)
 {
+  NS_ENSURE_ARG_POINTER(aTokHWVersion);
+
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown()) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   // handle removals/insertions
   if (PK11_GetSlotSeries(mSlot.get()) != mSeries) {
     nsresult rv = refreshTokenInfo(locker);
@@ -172,18 +188,21 @@ NS_IMETHODIMP nsPK11Token::GetTokenHWVer
       return rv;
     }
   }
   *aTokHWVersion = ToNewUnicode(mTokenHWVersion);
   if (!*aTokHWVersion) return NS_ERROR_OUT_OF_MEMORY;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPK11Token::GetTokenFWVersion(char16_t **aTokFWVersion)
+NS_IMETHODIMP
+nsPK11Token::GetTokenFWVersion(char16_t** aTokFWVersion)
 {
+  NS_ENSURE_ARG_POINTER(aTokFWVersion);
+
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown()) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   // handle removals/insertions
   if (PK11_GetSlotSeries(mSlot.get()) != mSeries) {
     nsresult rv = refreshTokenInfo(locker);
@@ -191,18 +210,21 @@ NS_IMETHODIMP nsPK11Token::GetTokenFWVer
       return rv;
     }
   }
   *aTokFWVersion = ToNewUnicode(mTokenFWVersion);
   if (!*aTokFWVersion) return NS_ERROR_OUT_OF_MEMORY;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPK11Token::GetTokenSerialNumber(char16_t **aTokSerialNum)
+NS_IMETHODIMP
+nsPK11Token::GetTokenSerialNumber(char16_t** aTokSerialNum)
 {
+  NS_ENSURE_ARG_POINTER(aTokSerialNum);
+
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown()) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   // handle removals/insertions
   if (PK11_GetSlotSeries(mSlot.get()) != mSeries) {
     nsresult rv = refreshTokenInfo(locker);
@@ -210,18 +232,21 @@ NS_IMETHODIMP nsPK11Token::GetTokenSeria
       return rv;
     }
   }
   *aTokSerialNum = ToNewUnicode(mTokenSerialNum);
   if (!*aTokSerialNum) return NS_ERROR_OUT_OF_MEMORY;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPK11Token::IsLoggedIn(bool *_retval)
+NS_IMETHODIMP
+nsPK11Token::IsLoggedIn(bool* _retval)
 {
+  NS_ENSURE_ARG_POINTER(_retval);
+
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown())
     return NS_ERROR_NOT_AVAILABLE;
 
   *_retval = PK11_IsLoggedIn(mSlot.get(), 0);
 
   return NS_OK;
 }
@@ -242,76 +267,89 @@ nsPK11Token::Login(bool force)
     if (NS_FAILED(rv)) return rv;
   }
   rv = setPassword(mSlot.get(), mUIContext, locker);
   if (NS_FAILED(rv)) return rv;
 
   return MapSECStatus(PK11_Authenticate(mSlot.get(), true, mUIContext));
 }
 
-NS_IMETHODIMP nsPK11Token::LogoutSimple()
+NS_IMETHODIMP
+nsPK11Token::LogoutSimple()
 {
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown())
     return NS_ERROR_NOT_AVAILABLE;
 
   // PK11_Logout() can fail if the user wasn't logged in beforehand. We want
   // this method to succeed even in this case, so we ignore the return value.
   Unused << PK11_Logout(mSlot.get());
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPK11Token::LogoutAndDropAuthenticatedResources()
+NS_IMETHODIMP
+nsPK11Token::LogoutAndDropAuthenticatedResources()
 {
   static NS_DEFINE_CID(kNSSComponentCID, NS_NSSCOMPONENT_CID);
 
   nsresult rv = LogoutSimple();
 
   if (NS_FAILED(rv))
     return rv;
 
   nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv));
   if (NS_FAILED(rv))
     return rv;
 
   return nssComponent->LogoutAuthenticatedPK11();
 }
 
-NS_IMETHODIMP nsPK11Token::Reset()
+NS_IMETHODIMP
+nsPK11Token::Reset()
 {
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown())
     return NS_ERROR_NOT_AVAILABLE;
 
   return MapSECStatus(PK11_ResetToken(mSlot.get(), nullptr));
 }
 
-NS_IMETHODIMP nsPK11Token::GetMinimumPasswordLength(int32_t *aMinimumPasswordLength)
+NS_IMETHODIMP
+nsPK11Token::GetMinimumPasswordLength(int32_t* aMinimumPasswordLength)
 {
+  NS_ENSURE_ARG_POINTER(aMinimumPasswordLength);
+
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown())
     return NS_ERROR_NOT_AVAILABLE;
 
   *aMinimumPasswordLength = PK11_GetMinimumPwdLength(mSlot.get());
 
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPK11Token::GetNeedsUserInit(bool *aNeedsUserInit)
+NS_IMETHODIMP
+nsPK11Token::GetNeedsUserInit(bool* aNeedsUserInit)
 {
+  NS_ENSURE_ARG_POINTER(aNeedsUserInit);
+
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown())
     return NS_ERROR_NOT_AVAILABLE;
 
   *aNeedsUserInit = PK11_NeedUserInit(mSlot.get());
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPK11Token::CheckPassword(const char16_t *password, bool *_retval)
+NS_IMETHODIMP
+nsPK11Token::CheckPassword(const char16_t* password, bool* _retval)
 {
+  // Note: It's OK for |password| to be null.
+  NS_ENSURE_ARG_POINTER(_retval);
+
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown())
     return NS_ERROR_NOT_AVAILABLE;
 
   NS_ConvertUTF16toUTF8 utf8Password(password);
   SECStatus srv =
     PK11_CheckUserPassword(mSlot.get(), const_cast<char*>(utf8Password.get()));
   if (srv != SECSuccess) {
@@ -322,42 +360,48 @@ NS_IMETHODIMP nsPK11Token::CheckPassword
       return mozilla::psm::GetXPCOMFromNSSError(error);
     }
   } else {
     *_retval =  true;
   }
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPK11Token::InitPassword(const char16_t *initialPassword)
+NS_IMETHODIMP
+nsPK11Token::InitPassword(const char16_t* initialPassword)
 {
+  // Note: It's OK for |initialPassword| to be null.
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown())
     return NS_ERROR_NOT_AVAILABLE;
 
   NS_ConvertUTF16toUTF8 utf8Password(initialPassword);
   return MapSECStatus(
     PK11_InitPin(mSlot.get(), "", const_cast<char*>(utf8Password.get())));
 }
 
 NS_IMETHODIMP
 nsPK11Token::GetAskPasswordTimes(int32_t* askTimes)
 {
+  NS_ENSURE_ARG_POINTER(askTimes);
+
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown())
     return NS_ERROR_NOT_AVAILABLE;
 
   int askTimeout;
   PK11_GetSlotPWValues(mSlot.get(), askTimes, &askTimeout);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPK11Token::GetAskPasswordTimeout(int32_t* askTimeout)
 {
+  NS_ENSURE_ARG_POINTER(askTimeout);
+
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown())
     return NS_ERROR_NOT_AVAILABLE;
 
   int askTimes;
   PK11_GetSlotPWValues(mSlot.get(), &askTimes, askTimeout);
   return NS_OK;
 }
@@ -369,18 +413,21 @@ nsPK11Token::SetAskPasswordDefaults(cons
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown())
     return NS_ERROR_NOT_AVAILABLE;
 
   PK11_SetSlotPWValues(mSlot.get(), askTimes, askTimeout);
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPK11Token::ChangePassword(const char16_t *oldPassword, const char16_t *newPassword)
+NS_IMETHODIMP
+nsPK11Token::ChangePassword(const char16_t* oldPassword,
+                            const char16_t* newPassword)
 {
+  // Note: It's OK for |oldPassword| and |newPassword| to be null.
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown())
     return NS_ERROR_NOT_AVAILABLE;
 
   NS_ConvertUTF16toUTF8 utf8OldPassword(oldPassword);
   NS_ConvertUTF16toUTF8 utf8NewPassword(newPassword);
 
   // nsCString.get() will return an empty string instead of nullptr even if it
@@ -388,40 +435,49 @@ NS_IMETHODIMP nsPK11Token::ChangePasswor
   // the empty string and for nullptr, so we can't just use get().
   // See Bug 447589.
   return MapSECStatus(PK11_ChangePW(
     mSlot.get(),
     (oldPassword ? const_cast<char*>(utf8OldPassword.get()) : nullptr),
     (newPassword ? const_cast<char*>(utf8NewPassword.get()) : nullptr)));
 }
 
-NS_IMETHODIMP nsPK11Token::IsHardwareToken(bool *_retval)
+NS_IMETHODIMP
+nsPK11Token::IsHardwareToken(bool* _retval)
 {
+  NS_ENSURE_ARG_POINTER(_retval);
+
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown())
     return NS_ERROR_NOT_AVAILABLE;
 
   *_retval = PK11_IsHW(mSlot.get());
 
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPK11Token::NeedsLogin(bool *_retval)
+NS_IMETHODIMP
+nsPK11Token::NeedsLogin(bool* _retval)
 {
+  NS_ENSURE_ARG_POINTER(_retval);
+
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown())
     return NS_ERROR_NOT_AVAILABLE;
 
   *_retval = PK11_NeedLogin(mSlot.get());
 
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPK11Token::IsFriendly(bool *_retval)
+NS_IMETHODIMP
+nsPK11Token::IsFriendly(bool* _retval)
 {
+  NS_ENSURE_ARG_POINTER(_retval);
+
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown())
     return NS_ERROR_NOT_AVAILABLE;
 
   *_retval = PK11_IsFriendly(mSlot.get());
 
   return NS_OK;
 }
@@ -439,37 +495,43 @@ nsPK11TokenDB::~nsPK11TokenDB()
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown()) {
     return;
   }
 
   shutdown(calledFromObject);
 }
 
-NS_IMETHODIMP nsPK11TokenDB::GetInternalKeyToken(nsIPK11Token **_retval)
+NS_IMETHODIMP
+nsPK11TokenDB::GetInternalKeyToken(nsIPK11Token** _retval)
 {
+  NS_ENSURE_ARG_POINTER(_retval);
+
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown()) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   UniquePK11SlotInfo slot(PK11_GetInternalKeySlot());
   if (!slot) {
     return NS_ERROR_FAILURE;
   }
 
   nsCOMPtr<nsIPK11Token> token = new nsPK11Token(slot.get());
   token.forget(_retval);
 
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPK11TokenDB::
-FindTokenByName(const char16_t* tokenName, nsIPK11Token **_retval)
+NS_IMETHODIMP
+nsPK11TokenDB::FindTokenByName(const char16_t* tokenName, nsIPK11Token** _retval)
 {
+  // Note: It's OK for |tokenName| to be null.
+  NS_ENSURE_ARG_POINTER(_retval);
+
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown()) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   NS_ConvertUTF16toUTF8 utf8TokenName(tokenName);
   UniquePK11SlotInfo slot(
     PK11_FindSlotByName(const_cast<char*>(utf8TokenName.get())));
@@ -481,16 +543,18 @@ FindTokenByName(const char16_t* tokenNam
   token.forget(_retval);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPK11TokenDB::ListTokens(nsISimpleEnumerator** _retval)
 {
+  NS_ENSURE_ARG_POINTER(_retval);
+
   nsNSSShutDownPreventionLock locker;
   if (isAlreadyShutDown()) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   nsCOMPtr<nsIMutableArray> array = do_CreateInstance(NS_ARRAY_CONTRACTID);
   if (!array) {
     return NS_ERROR_FAILURE;