Skip to content

Commit 10cc254

Browse files
fowleshybrist
authored andcommitted
src: fix null deref in AllocatedBuffer::clear
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>
1 parent 4299e97 commit 10cc254

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/env-inl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,10 @@ inline AllocatedBuffer::~AllocatedBuffer() {
10031003

10041004
inline void AllocatedBuffer::clear() {
10051005
uv_buf_t buf = release();
1006-
env_->Free(buf.base, buf.len);
1006+
if (buf.base != nullptr) {
1007+
CHECK_NOT_NULL(env_);
1008+
env_->Free(buf.base, buf.len);
1009+
}
10071010
}
10081011

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

0 commit comments

Comments
 (0)