From 27d3201502dffa74d0d6b861db33c5439ec1e002 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Tue, 20 Dec 2022 15:55:19 -0600 Subject: [PATCH] src: check size of args before using for exec_path If we are in an artifically created Environment that has no args set, and uv_exepath returns an error (for instance, if /proc is not mounted on a Linux system), then we crash with a nullptr deref attempting to use argv[0]. Fixes: https://github.com/nodejs/node/issues/45901 PR-URL: https://github.com/nodejs/node/pull/45902 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- src/env.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/env.cc b/src/env.cc index 129f070873517f..9e83b3ddebbb98 100644 --- a/src/env.cc +++ b/src/env.cc @@ -619,7 +619,7 @@ std::string GetExecPath(const std::vector& argv) { std::string exec_path; if (uv_exepath(exec_path_buf, &exec_path_len) == 0) { exec_path = std::string(exec_path_buf, exec_path_len); - } else { + } else if (argv.size() > 0) { exec_path = argv[0]; }