crypto: do not move half-filled write head
authorFedor Indutny <fedor.indutny@gmail.com>
Tue, 25 Jun 2013 21:31:10 +0000 (23:31 +0200)
committerFedor Indutny <fedor.indutny@gmail.com>
Wed, 26 Jun 2013 10:36:56 +0000 (12:36 +0200)
Might cause write head running over read head, when there were no
allocation and `Commit()` was called. Source of at least one test
failure on windows (`simple/test-https-drain.js`).

src/node_crypto_bio.cc

index 9afaa3d..2932f64 100644 (file)
@@ -315,6 +315,7 @@ void NodeBIO::Write(const char* data, size_t size) {
 
     // Go to next buffer if there still are some bytes to write
     if (left != 0) {
+      assert(write_head_->write_pos_ == kBufferLength);
       TryAllocateForWrite();
       write_head_ = write_head_->next_;
     }
@@ -342,7 +343,8 @@ void NodeBIO::Commit(size_t size) {
   // Allocate new buffer if write head is full,
   // and there're no other place to go
   TryAllocateForWrite();
-  write_head_ = write_head_->next_;
+  if (write_head_->write_pos_ == kBufferLength)
+    write_head_ = write_head_->next_;
 }