Bug 1280844 - Move some null checks earlier in lib/. r?mt. draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 21 Jun 2016 09:59:17 +1000
changeset 380172 26f0266070d50811a7d98c90ab92797f272d860c
parent 380171 cb51d2f903ca1ceda8461644289df0da4d4ab67b
child 380173 8aa601ca7d3c6ab2f7381774e759c57468d510d9
push id21158
push usernnethercote@mozilla.com
push dateMon, 20 Jun 2016 23:59:39 +0000
reviewersmt
bugs1280844
milestone50.0a1
Bug 1280844 - Move some null checks earlier in lib/. r?mt. MozReview-Commit-ID: DuYwLzxp2Gr
security/nss/lib/ssl/sslmutex.c
--- a/security/nss/lib/ssl/sslmutex.c
+++ b/security/nss/lib/ssl/sslmutex.c
@@ -389,30 +389,34 @@ sslMutex_Init(sslMutex *pMutex, int shar
 SECStatus
 sslMutex_Destroy(sslMutex *pMutex, PRBool processLocal)
 {
     HANDLE hMutex;
     int rv;
     int retvalue = SECSuccess;
 
     PR_ASSERT(pMutex != 0);
+    if (!pMutex) {
+        PORT_SetError(PR_INVALID_ARGUMENT_ERROR);
+        return SECFailure;
+    }
+
     if (PR_FALSE == pMutex->isMultiProcess) {
         return single_process_sslMutex_Destroy(pMutex);
     }
 
 /*  multi-process mode */
 #ifdef WINNT
     /* on NT, get rid of the PRLock used for fibers within a process */
     retvalue = sslMutex_2LevelDestroy(pMutex);
 #endif
 
     PR_ASSERT(pMutex->u.sslMutx != 0 &&
               pMutex->u.sslMutx != INVALID_HANDLE_VALUE);
-    if (!pMutex || (hMutex = pMutex->u.sslMutx) == 0 ||
-        hMutex == INVALID_HANDLE_VALUE) {
+    if ((hMutex = pMutex->u.sslMutx) == 0 || hMutex == INVALID_HANDLE_VALUE) {
         PORT_SetError(PR_INVALID_ARGUMENT_ERROR);
         return SECFailure;
     }
 
     rv = CloseHandle(hMutex); /* ignore error */
     if (!processLocal && rv) {
         pMutex->u.sslMutx = hMutex = INVALID_HANDLE_VALUE;
     }
@@ -425,24 +429,28 @@ sslMutex_Destroy(sslMutex *pMutex, PRBoo
 
 int
 sslMutex_Unlock(sslMutex *pMutex)
 {
     BOOL success = FALSE;
     HANDLE hMutex;
 
     PR_ASSERT(pMutex != 0);
+    if (!pMutex) {
+        PORT_SetError(PR_INVALID_ARGUMENT_ERROR);
+        return SECFailure;
+    }
+
     if (PR_FALSE == pMutex->isMultiProcess) {
         return single_process_sslMutex_Unlock(pMutex);
     }
 
     PR_ASSERT(pMutex->u.sslMutx != 0 &&
               pMutex->u.sslMutx != INVALID_HANDLE_VALUE);
-    if (!pMutex || (hMutex = pMutex->u.sslMutx) == 0 ||
-        hMutex == INVALID_HANDLE_VALUE) {
+    if ((hMutex = pMutex->u.sslMutx) == 0 || hMutex == INVALID_HANDLE_VALUE) {
         PORT_SetError(PR_INVALID_ARGUMENT_ERROR);
         return SECFailure;
     }
     success = ReleaseMutex(hMutex);
     if (!success) {
         nss_MD_win32_map_default_error(GetLastError());
         return SECFailure;
     }
@@ -457,30 +465,33 @@ sslMutex_Unlock(sslMutex *pMutex)
 int
 sslMutex_Lock(sslMutex *pMutex)
 {
     HANDLE hMutex;
     DWORD event;
     DWORD lastError;
     SECStatus rv;
     SECStatus retvalue = SECSuccess;
+
     PR_ASSERT(pMutex != 0);
+    if (!pMutex) {
+        PORT_SetError(PR_INVALID_ARGUMENT_ERROR);
+        return SECFailure;
+    }
 
     if (PR_FALSE == pMutex->isMultiProcess) {
         return single_process_sslMutex_Lock(pMutex);
     }
 #ifdef WINNT
-    /* lock first to preserve from other threads/fibers
-       in the same process */
+    /* lock first to preserve from other threads/fibers in the same process */
     retvalue = single_process_sslMutex_Lock(pMutex);
 #endif
     PR_ASSERT(pMutex->u.sslMutx != 0 &&
               pMutex->u.sslMutx != INVALID_HANDLE_VALUE);
-    if (!pMutex || (hMutex = pMutex->u.sslMutx) == 0 ||
-        hMutex == INVALID_HANDLE_VALUE) {
+    if ((hMutex = pMutex->u.sslMutx) == 0 || hMutex == INVALID_HANDLE_VALUE) {
         PORT_SetError(PR_INVALID_ARGUMENT_ERROR);
         return SECFailure; /* what else ? */
     }
     /* acquire the mutex to be the only owner accross all other processes */
     event = WaitForSingleObject(hMutex, INFINITE);
     switch (event) {
         case WAIT_OBJECT_0:
         case WAIT_ABANDONED: