From 2f84e3b4a757f1572deb62938238466d9a071b0f Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Fri, 8 Apr 2022 17:17:51 -0400 Subject: [PATCH] src: fix coverity report Fix coverity report about possibly dereferencing a null. If the the buffer.data != nullptr check indicates that the buffer was null, then relying on the value in buffer_size is no longer safe. The later call to uv_pipe_getpeername depends on the buffer_size being correct to avoid deferencing buffer.data if it is not big enough. Signed-off-by: Michael Dawson PR-URL: https://github.com/nodejs/node/pull/42663 Reviewed-By: Darshan Sen Reviewed-By: James M Snell --- src/node_report_utils.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/node_report_utils.cc b/src/node_report_utils.cc index 82ed385ad176bd..6d8b211b6d1c51 100644 --- a/src/node_report_utils.cc +++ b/src/node_report_utils.cc @@ -95,6 +95,8 @@ static void ReportPipeEndpoints(uv_handle_t* h, JSONWriter* writer) { buffer = MallocedBuffer(buffer_size); if (buffer.data != nullptr) { rc = uv_pipe_getsockname(&handle->pipe, buffer.data, &buffer_size); + } else { + buffer_size = 0; } } if (rc == 0 && buffer_size != 0 && buffer.data != nullptr) {