Skip to content

Commit

Permalink
src: fix null deref in AllocatedBuffer::clear
Browse files Browse the repository at this point in the history
An empty buffer can have a null environment.  Previously, we were
getting away with with this, but -fsanitize=null in clang caught it.

PR-URL: #32892
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Jan Krems <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
  • Loading branch information
fowles authored and BethGriggs committed Apr 27, 2020
1 parent fa71073 commit 4221b1c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,10 @@ inline AllocatedBuffer::~AllocatedBuffer() {

inline void AllocatedBuffer::clear() {
uv_buf_t buf = release();
env_->Free(buf.base, buf.len);
if (buf.base != nullptr) {
CHECK_NOT_NULL(env_);
env_->Free(buf.base, buf.len);
}
}

// It's a bit awkward to define this Buffer::New() overload here, but it
Expand Down

0 comments on commit 4221b1c

Please sign in to comment.