Skip to content

Commit 0fdc55f

Browse files
fowlesBridgeAR
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 <[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]>
1 parent faeb408 commit 0fdc55f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/env-inl.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,10 @@ inline AllocatedBuffer::~AllocatedBuffer() {
10291029

10301030
inline void AllocatedBuffer::clear() {
10311031
uv_buf_t buf = release();
1032-
env_->Free(buf.base, buf.len);
1032+
if (buf.base != nullptr) {
1033+
CHECK_NOT_NULL(env_);
1034+
env_->Free(buf.base, buf.len);
1035+
}
10331036
}
10341037

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

0 commit comments

Comments
 (0)