-
Notifications
You must be signed in to change notification settings - Fork 455
CDRIVER-5756 Coverity fixes #1867
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
base: master
Are you sure you want to change the base?
Conversation
CID: 100057
CID: 100087
CID: 115840, 115848, 115851, 115853
CID: 134019
CID: 138986
CID: 138989
CID: 156373
CID: 157950
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.
A few comments and questions.
bson_mutex_lock (&topology->tpld_modification_mtx); | ||
for (size_t i = 0u; i < n_rtt_monitors; i++) { | ||
server_monitor = mongoc_set_get_item (topology->rtt_monitors, i); | ||
mongoc_server_monitor_request_shutdown (server_monitor); | ||
} | ||
bson_mutex_unlock (&topology->tpld_modification_mtx); |
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'm not sure if this mutex is relevant here. Do you have a link to the Coverity warning related to these lines?
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 sent you the link in a DM.
jsn->jprs = (jsonsl_jpr_t *)malloc(sizeof(jsonsl_jpr_t) * njprs); | ||
if (!jsn->jprs) { | ||
return; | ||
} |
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.
jsn->jprs = (jsonsl_jpr_t *)malloc(sizeof(jsonsl_jpr_t) * njprs); | |
if (!jsn->jprs) { | |
return; | |
} | |
jsn->jprs = (jsonsl_jpr_t *) bson_malloc (sizeof (jsonsl_jpr_t) * njprs); |
Suggest using bson_malloc
. bson_malloc
already checks (and aborts) if allocation fails. I expect that will fix the Coverity warning. Using bson_malloc
ensures allocators set with bson_mem_set_vtable
are used.
Also replace free(jsn->jprs);
with bson_free(jsn->jprs);
jsn->jpr_root = (size_t*)calloc(1, sizeof(size_t) * njprs * jsn->levels_max); | ||
if (!jsn->jpr_root) { | ||
free(jsn->jprs); | ||
return; | ||
} |
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.
jsn->jpr_root = (size_t*)calloc(1, sizeof(size_t) * njprs * jsn->levels_max); | |
if (!jsn->jpr_root) { | |
free(jsn->jprs); | |
return; | |
} | |
jsn->jpr_root = (size_t *) bson_malloc0 (sizeof (size_t) * njprs * jsn->levels_max); |
Similarly, use bson_malloc0
in place of calloc
. Suggest updating other malloc
/ free
calls in this file.
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.
OK. That makes sense. Should I do that as a drive-by in this PR, or a separate PR?
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 think it is OK to include in this PR. Though the other malloc
calls check their returns, I think it is a related enough change to include in this PR.
@@ -262,14 +262,20 @@ static const uint8_t mongoc_b64rmap_invalid = 0xff; | |||
#if defined(BSON_OS_UNIX) |
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 expect this entire #if / #else / #endif
block can be removed. Add #include <common-thread-private.h>
and instead use the bson_once*
and BSON_ONCE*
APIs. bson_once
already has an assert.
@@ -622,9 +622,10 @@ _bson_json_read_integer (bson_json_reader_t *reader, uint64_t val, int64_t sign) | |||
|
|||
if (rs == BSON_JSON_REGULAR) { | |||
BASIC_CB_BAIL_IF_NOT_NORMAL ("integer"); | |||
BSON_ASSERT (mlib_in_range (int, len)); |
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.
Rather than assert, suggest checking if len
is greater than INT_MAX
and returning an error. I expect this applies to all types being read. That may avoid a possible crash if the input JSON has a very large (over INT_MAX length) key.
Here is a commit with a test (which is only run when the environment variable MONGOC_TEST_LARGE_ALLOCATIONS=ON
is defined) and suggested change.
This PR fixes some small Coverity issues (w/ full Evergreen patch build).
@kevinAlbs I wasn't sure who would be available to review, so please feel free to adjust the reviewers as needed.