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 <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
  • Loading branch information
fowles authored and jkrems committed Apr 21, 2020
1 parent 4299e97 commit 10cc254
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 @@ -1003,7 +1003,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 10cc254

Please sign in to comment.