diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2019-02-08 04:04:07 +0300 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2019-02-12 05:26:38 +0300 |
commit | af83f6af5daf5b91f790cb6b9bf61f1ca566ccd0 (patch) | |
tree | 88244e3760b72364eb0acb68775c77780561ac18 /src/node_process_object.cc | |
parent | 9e84a26cb3d390a6ce051b75c892094fff233f92 (diff) |
process: normalize process.execPath in CreateProcessObject()
Directly normalize `process.execPath` using `uv_fs_realpath`
on OpenBSD before serializing it into the process object,
instead of using `require('fs')` to normalize and override
the path in `bootstrap/node.js`.
PR-URL: https://github.com/nodejs/node/pull/26002
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_process_object.cc')
-rw-r--r-- | src/node_process_object.cc | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/src/node_process_object.cc b/src/node_process_object.cc index 159d9fdc407..2f47b21f699 100644 --- a/src/node_process_object.cc +++ b/src/node_process_object.cc @@ -273,21 +273,34 @@ MaybeLocal<Object> CreateProcessObject( // process.execPath { - size_t exec_path_len = 2 * PATH_MAX; - std::vector<char> exec_path(exec_path_len); - Local<String> exec_path_value; - if (uv_exepath(exec_path.data(), &exec_path_len) == 0) { - exec_path_value = String::NewFromUtf8(env->isolate(), - exec_path.data(), - NewStringType::kInternalized, - exec_path_len).ToLocalChecked(); + char exec_path_buf[2 * PATH_MAX]; + size_t exec_path_len = sizeof(exec_path_buf); + 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 { - exec_path_value = String::NewFromUtf8(env->isolate(), args[0].c_str(), - NewStringType::kInternalized).ToLocalChecked(); + exec_path = args[0]; } - process->Set(env->context(), - FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"), - exec_path_value).FromJust(); + // On OpenBSD process.execPath will be relative unless we + // get the full path before process.execPath is used. +#if defined(__OpenBSD__) + uv_fs_t req; + req.ptr = nullptr; + if (0 == + uv_fs_realpath(env->event_loop(), &req, exec_path.c_str(), nullptr)) { + CHECK_NOT_NULL(req.ptr); + exec_path = std::string(static_cast<char*>(req.ptr)); + } +#endif + process + ->Set(env->context(), + FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"), + String::NewFromUtf8(env->isolate(), + exec_path.c_str(), + NewStringType::kInternalized, + exec_path.size()) + .ToLocalChecked()) + .FromJust(); } // process.debugPort |