Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: net/socket/ssl_server_socket_nss.cc

Issue 7399025: Fix instability in SSL client/server sockets (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update FakeSocketTest. Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/socket/ssl_server_socket_nss.h" 5 #include "net/socket/ssl_server_socket_nss.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <winsock2.h> 8 #include <winsock2.h>
9 #endif 9 #endif
10 10
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 418
419 if (!completed_handshake_) 419 if (!completed_handshake_)
420 return; 420 return;
421 421
422 if (user_write_buf_) { 422 if (user_write_buf_) {
423 int rv = DoWriteLoop(result); 423 int rv = DoWriteLoop(result);
424 if (rv != ERR_IO_PENDING) 424 if (rv != ERR_IO_PENDING)
425 DoWriteCallback(rv); 425 DoWriteCallback(rv);
426 } else { 426 } else {
427 // Ensure that any queued ciphertext is flushed. 427 // Ensure that any queued ciphertext is flushed.
428 DoTransportIO(); 428 DoTransportIO();
wtc 2011/07/21 00:27:12 IMPORTANT: We may get here via this call stack:
Sergey Ulanov 2011/07/21 00:33:28 BufferSendComplete() is called from Write callback
429 } 429 }
430 } 430 }
431 431
432 void SSLServerSocketNSS::OnRecvComplete(int result) { 432 void SSLServerSocketNSS::OnRecvComplete(int result) {
433 if (next_handshake_state_ == STATE_HANDSHAKE) { 433 if (next_handshake_state_ == STATE_HANDSHAKE) {
434 // In handshake phase. 434 // In handshake phase.
435 OnHandshakeIOComplete(result); 435 OnHandshakeIOComplete(result);
436 return; 436 return;
437 } 437 }
438 438
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 char *buf; 521 char *buf;
522 memio_GetReadParams(nss_bufs_, &buf); 522 memio_GetReadParams(nss_bufs_, &buf);
523 memcpy(buf, recv_buffer_->data(), result); 523 memcpy(buf, recv_buffer_->data(), result);
524 } 524 }
525 recv_buffer_ = NULL; 525 recv_buffer_ = NULL;
526 memio_PutReadResult(nss_bufs_, MapErrorToNSS(result)); 526 memio_PutReadResult(nss_bufs_, MapErrorToNSS(result));
527 transport_recv_busy_ = false; 527 transport_recv_busy_ = false;
528 OnRecvComplete(result); 528 OnRecvComplete(result);
529 } 529 }
530 530
531 // Do network I/O between the given buffer and the given socket. 531 // Do as much as possible network I/O between the buffer and the
wtc 2011/07/21 00:27:12 as much as possible network I/O => as much network
Sergey Ulanov 2011/07/21 00:51:15 Done.
532 // Return true if some I/O performed, false otherwise (error or ERR_IO_PENDING) 532 // transport socket. Return true if some I/O performed, false
533 // otherwise (error or ERR_IO_PENDING).
533 bool SSLServerSocketNSS::DoTransportIO() { 534 bool SSLServerSocketNSS::DoTransportIO() {
534 bool network_moved = false; 535 bool network_moved = false;
535 if (nss_bufs_ != NULL) { 536 if (nss_bufs_ != NULL) {
536 int nsent = BufferSend(); 537 int rv;
537 int nreceived = BufferRecv(); 538 // Read and write as much data as we can. Loops are neccessary
538 network_moved = (nsent > 0 || nreceived >= 0); 539 // because Read() and Write() may return synchronously.
540 do {
541 rv = BufferSend();
542 if (rv > 0)
543 network_moved = true;
544 } while (rv > 0);
wtc 2011/07/21 00:27:12 IMPORTANT: Unless this BufferSend loop empties the
Sergey Ulanov 2011/07/21 00:33:28 This loop can exit in 3 cases: 1. There is no pen
wtc 2011/07/21 00:56:45 It is case 2 that I am worried about. The caller
Sergey Ulanov 2011/07/21 01:09:51 Yes, write callback doesn't mean that the data was
545 do {
546 rv = BufferRecv();
547 if (rv >= 0)
548 network_moved = true;
549 } while (rv > 0);
wtc 2011/07/21 00:27:12 The loop around BufferRecv should not be necessary
Sergey Ulanov 2011/07/21 00:51:15 Yes, agree, this loop isn't neccessary, but it may
539 } 550 }
540 return network_moved; 551 return network_moved;
541 } 552 }
542 553
543 int SSLServerSocketNSS::DoPayloadRead() { 554 int SSLServerSocketNSS::DoPayloadRead() {
544 DCHECK(user_read_buf_); 555 DCHECK(user_read_buf_);
545 DCHECK_GT(user_read_buf_len_, 0); 556 DCHECK_GT(user_read_buf_len_, 0);
546 int rv = PR_Read(nss_fd_, user_read_buf_->data(), user_read_buf_len_); 557 int rv = PR_Read(nss_fd_, user_read_buf_->data(), user_read_buf_len_);
547 if (rv >= 0) 558 if (rv >= 0)
548 return rv; 559 return rv;
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 // We must call EnsureOCSPInit() here, on the IO thread, to get the IO loop 752 // We must call EnsureOCSPInit() here, on the IO thread, to get the IO loop
742 // by MessageLoopForIO::current(). 753 // by MessageLoopForIO::current().
743 // X509Certificate::Verify() runs on a worker thread of CertVerifier. 754 // X509Certificate::Verify() runs on a worker thread of CertVerifier.
744 EnsureOCSPInit(); 755 EnsureOCSPInit();
745 #endif 756 #endif
746 757
747 return OK; 758 return OK;
748 } 759 }
749 760
750 } // namespace net 761 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698