From 4221b1c8c942912b14d05ad03c24f9009b26ba94 Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Thu, 16 Apr 2020 19:30:08 -0400 Subject: [PATCH] src: fix null deref in AllocatedBuffer::clear MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/pull/32892 Reviewed-By: Anna Henningsen Reviewed-By: David Carlier Reviewed-By: Jan Krems Reviewed-By: James M Snell Reviewed-By: Juan José Arboleda --- src/env-inl.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/env-inl.h b/src/env-inl.h index 853c74f3e5b0f1..9ba5bebe00cb27 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -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