Bug 733521: Hold handshake lock across all accesses of handshake information in ssl3_GatherCompleteHandshake, r=wtc
authorBrian Smith <bsmith@mozilla.com>
Mon, 06 May 2013 14:06:12 -0700
changeset 10766 cf3b9b27172ea4466692024944054748ad88d876
parent 10765 6fb9ff40d0548e3b3289e580091b668a37003a63
child 10767 776fced32705ef7b3f4d7bf314c4538ac8367019
push id76
push userbsmith@mozilla.com
push dateMon, 06 May 2013 21:08:30 +0000
reviewerswtc
bugs733521
Bug 733521: Hold handshake lock across all accesses of handshake information in ssl3_GatherCompleteHandshake, r=wtc
lib/ssl/ssl3gthr.c
--- a/lib/ssl/ssl3gthr.c
+++ b/lib/ssl/ssl3gthr.c
@@ -276,44 +276,43 @@ ssl3_GatherCompleteHandshake(sslSocket *
     SSL3Ciphertext cText;
     int            rv;
     PRBool         canFalseStart = PR_FALSE;
 
     SSL_TRC(30, ("ssl3_GatherCompleteHandshake"));
 
     PORT_Assert( ss->opt.noLocks || ssl_HaveRecvBufLock(ss) );
     do {
-	PRBool handleRecordNow;
+	PRBool handleRecordNow = PR_FALSE;
 
 	ssl_GetSSL3HandshakeLock(ss);
 
 	/* Without this, we may end up wrongly reporting
 	 * SSL_ERROR_RX_UNEXPECTED_* errors if we receive any records from the
 	 * peer while we are waiting to be restarted.
 	 */
-	rv = ss->ssl3.hs.restartTarget == NULL ? SECSuccess : SECFailure;
-	if (rv != SECSuccess) {
+	if (ss->ssl3.hs.restartTarget) {
 	    ssl_ReleaseSSL3HandshakeLock(ss);
 	    PORT_SetError(PR_WOULD_BLOCK_ERROR);
 	    return (int) SECFailure;
 	}
 
 	/* Treat an empty msgState like a NULL msgState. (Most of the time
 	 * when ssl3_HandleHandshake returns SECWouldBlock, it leaves
 	 * behind a non-NULL but zero-length msgState).
 	 * Test: async_cert_restart_server_sends_hello_request_first_in_separate_record
 	 */
-	if (ss->ssl3.hs.msgState.buf != NULL) {
+	if (ss->ssl3.hs.msgState.buf) {
 	    if (ss->ssl3.hs.msgState.len == 0) {
 		ss->ssl3.hs.msgState.buf = NULL;
+	    } else {
+		handleRecordNow = PR_TRUE;
 	    }
 	}
 
-	handleRecordNow = ss->ssl3.hs.msgState.buf != NULL;
-
 	ssl_ReleaseSSL3HandshakeLock(ss);
 
 	if (handleRecordNow) {
 	    /* ssl3_HandleHandshake previously returned SECWouldBlock and the
 	     * as-yet-unprocessed plaintext of that previous handshake record.
 	     * We need to process it now before we overwrite it with the next
 	     * handshake record.
 	     */