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_process_object.cc | |
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_process_object.cc')
-rw-r--r-- | src/node_process_object.cc | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/node_process_object.cc b/src/node_process_object.cc index a1bf90c8d69..7cf8c125009 100644 --- a/src/node_process_object.cc +++ b/src/node_process_object.cc @@ -32,11 +32,11 @@ using v8::Value; static void ProcessTitleGetter(Local<Name> property, const PropertyCallbackInfo<Value>& info) { - char buffer[512]; - uv_get_process_title(buffer, sizeof(buffer)); + std::string title = GetProcessTitle("node"); info.GetReturnValue().Set( - String::NewFromUtf8(info.GetIsolate(), buffer, NewStringType::kNormal) - .ToLocalChecked()); + String::NewFromUtf8(info.GetIsolate(), title.data(), + NewStringType::kNormal, title.size()) + .ToLocalChecked()); } static void ProcessTitleSetter(Local<Name> property, |