diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2020-02-04 17:52:39 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-02-08 01:49:18 +0300 |
commit | d394dd78de600e89ceea02b3582435e50f249aa4 (patch) | |
tree | 05ed92f334ac4b111c7af4911637da53ab57dbae /src/node_v8_platform-inl.h | |
parent | 7df429808ca336b6aa868a9ae1ceb6117c68e7c4 (diff) |
src: fix OOB reads in process.title getter
The getter passed a stack-allocated, fixed-size buffer to
uv_get_process_title() but neglected to check the return value.
When the total length of the command line arguments exceeds the size of
the buffer, libuv returns UV_ENOBUFS and doesn't modify the contents of
the buffer. The getter then proceeded to return whatever garbage was on
the stack at the time of the call, quite possibly reading beyond the
end of the buffer.
Add a GetProcessTitle() helper that reads the process title into a
dynamically allocated buffer that is resized when necessary.
Fixes: https://github.com/nodejs/node/issues/31631
PR-URL: https://github.com/nodejs/node/pull/31633
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/node_v8_platform-inl.h')
-rw-r--r-- | src/node_v8_platform-inl.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/node_v8_platform-inl.h b/src/node_v8_platform-inl.h index ecd8f21d1a2..0f4a98a9855 100644 --- a/src/node_v8_platform-inl.h +++ b/src/node_v8_platform-inl.h @@ -21,12 +21,12 @@ class NodeTraceStateObserver : public v8::TracingController::TraceStateObserver { public: inline void OnTraceEnabled() override { - char name_buffer[512]; - if (uv_get_process_title(name_buffer, sizeof(name_buffer)) == 0) { + std::string title = GetProcessTitle(""); + if (!title.empty()) { // Only emit the metadata event if the title can be retrieved // successfully. Ignore it otherwise. TRACE_EVENT_METADATA1( - "__metadata", "process_name", "name", TRACE_STR_COPY(name_buffer)); + "__metadata", "process_name", "name", TRACE_STR_COPY(title.c_str())); } TRACE_EVENT_METADATA1("__metadata", "version", |