Skip to content

Commit e09f7f0

Browse files
addaleaxdanielleadams
authored andcommitted
src: limit GetProcessTitle() result to 1MB
`GetProcessTitle()` otherwise runs an infinite loop when `uv_setup_argv()` has not been called (yet). This is a problem e.g. in assertions from static constructors, which run before `main()` and thus before `argc` and `argv` become available. To solve that, do not allocate more than 1MB of storage for the title and bail out if we reach that point. PR-URL: #35492 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 5790c40 commit e09f7f0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/util.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ std::string GetProcessTitle(const char* default_title) {
144144
if (rc == 0)
145145
break;
146146

147-
if (rc != UV_ENOBUFS)
147+
// If uv_setup_args() was not called, `uv_get_process_title()` will always
148+
// return `UV_ENOBUFS`, no matter the input size. Guard against a possible
149+
// infinite loop by limiting the buffer size.
150+
if (rc != UV_ENOBUFS || buf.size() >= 1024 * 1024)
148151
return default_title;
149152

150153
buf.resize(2 * buf.size());

0 commit comments

Comments
 (0)