-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inspector: fix Coverity defects #12272
Conversation
src/inspector_io.cc
Outdated
@@ -236,6 +236,7 @@ void InspectorIo::WriteCbIO(uv_async_t* async) { | |||
template<typename Transport> | |||
void InspectorIo::WorkerRunIO() { | |||
uv_loop_t loop; | |||
loop.data = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to libuv docs, this should be initialized in the next line with uv_loop_init()
:
- void* uv_loop_t.data
- Space for user-defined arbitrary data. libuv does not use this field. libuv does, however, initialize it to NULL in
uv_loop_init()
, and it poisons the value (on debug builds) onuv_loop_close()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think Coverity is aware of the fact...
CID 166789 (# 1 of 1): Uninitialized pointer read (UNINIT)
2. uninit_use_in_call: Using uninitialized value loop.data when calling uv_loop_init."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I’m missing something obvious, the libuv docs are lying:
Lines 36 to 38 in 2d3d4cc
saved_data = loop->data; | |
memset(loop, 0, sizeof(*loop)); | |
loop->data = saved_data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But not for long: libuv/libuv#1299
Alternative syntax: uv_loop_t loop = uv_loop_t()
(or auto loop = uv_loop_t()
if you don't like to repeat yourself), that zeroes out all fields.
src/inspector_io.cc
Outdated
@@ -236,6 +236,7 @@ void InspectorIo::WriteCbIO(uv_async_t* async) { | |||
template<typename Transport> | |||
void InspectorIo::WorkerRunIO() { | |||
uv_loop_t loop; | |||
loop.data = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I’m missing something obvious, the libuv docs are lying:
Lines 36 to 38 in 2d3d4cc
saved_data = loop->data; | |
memset(loop, 0, sizeof(*loop)); | |
loop->data = saved_data; |
src/inspector_io.cc
Outdated
@@ -236,6 +236,7 @@ void InspectorIo::WriteCbIO(uv_async_t* async) { | |||
template<typename Transport> | |||
void InspectorIo::WorkerRunIO() { | |||
uv_loop_t loop; | |||
loop.data = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But not for long: libuv/libuv#1299
Alternative syntax: uv_loop_t loop = uv_loop_t()
(or auto loop = uv_loop_t()
if you don't like to repeat yourself), that zeroes out all fields.
src/inspector_io.cc
Outdated
if (0 == uv_fs_realpath(&loop, &req, script_name_.c_str(), nullptr)) | ||
req.ptr = nullptr; | ||
err = uv_fs_realpath(&loop, &req, script_name_.c_str(), nullptr); | ||
if (0 == err && req.ptr != nullptr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nullptr check shouldn't be necessary but perhaps coverity isn't smart enough to figure that out... I'd turn it into a CHECK_NE(req.ptr, nullptr)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM sans comment.
src/inspector_io.cc
Outdated
if (0 == uv_fs_realpath(&loop, &req, script_name_.c_str(), nullptr)) | ||
req.ptr = nullptr; | ||
err = uv_fs_realpath(&loop, &req, script_name_.c_str(), nullptr); | ||
if (0 == err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to assign to err
anymore, that would keep the diff smaller.
Landed as 42be835 |
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
inspector: minor fixes