Skip to content

Commit e5791f7

Browse files
committed
crypto: fix another over-run in bio
When doing `FreeEmpty`, `NodeBIO` skips pre-allocated `head_` buffer. However this might lead to double-freeing buffers since in `~NodeBIO()` we're starting deallocation from `head_` buffer.
1 parent 350fc80 commit e5791f7

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/node_crypto_bio.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,21 +232,24 @@ void NodeBIO::FreeEmpty() {
232232
if (cur == write_head_ || cur == read_head_)
233233
return;
234234

235+
Buffer* prev = child;
235236
while (cur != read_head_) {
236-
// Skip embedded buffer
237+
// Skip embedded buffer, and continue deallocating again starting from it
237238
if (cur == &head_) {
239+
prev->next_ = cur;
240+
prev = cur;
238241
cur = head_.next_;
239242
continue;
240243
}
241244
assert(cur != write_head_);
242245
assert(cur->write_pos_ == cur->read_pos_);
243246

244247
Buffer* next = cur->next_;
245-
child->next_ = next;
246248
delete cur;
247-
248249
cur = next;
249250
}
251+
assert(prev == child || prev == &head_);
252+
prev->next_ = cur;
250253
}
251254

252255

0 commit comments

Comments
 (0)