Skip to content

Commit 7c12ebc

Browse files
authored
CDRIVER-4091 - Truncation in strncpy() causes build error (#829)
https://jira.mongodb.org/browse/CDRIVER-4091 gcc 9.3.0 complains that because the strncpy() call uses the source's size as a bound, the trailing NULL will not be copied. Replaced with: updated allocation size of destination to include room for the NULL character eliminated redundant srlen() changed strncpy() call to strcpy(), which includes the trailing NULL Signed-off-by: Jesse Williamson <[email protected]>
1 parent 0da8f1a commit 7c12ebc

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/libmongoc/tests/test-mongoc-mongohouse.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ cmd_succeeded_cb (const mongoc_apm_command_succeeded_t *event)
151151

152152
/* Store cursor information from our initial find. */
153153
if (strcmp (cmd, "find") == 0) {
154-
const char *temp;
155154

156155
BSON_ASSERT (!test->parsed_cursor);
157156

@@ -164,9 +163,8 @@ cmd_succeeded_cb (const mongoc_apm_command_succeeded_t *event)
164163
BSON_ASSERT (bson_iter_find_descendant (&iter, "cursor.ns", &child_iter));
165164
BSON_ASSERT (BSON_ITER_HOLDS_UTF8 (&child_iter));
166165

167-
temp = bson_iter_utf8 (&child_iter, NULL);
168-
test->cursor_ns = (char *) bson_malloc0 (strlen (temp));
169-
strncpy (test->cursor_ns, temp, strlen (temp));
166+
test->cursor_ns = bson_strdup(bson_iter_utf8(&child_iter, NULL));
167+
BSON_ASSERT (NULL != test->cursor_ns);
170168

171169
test->parsed_cursor = true;
172170

0 commit comments

Comments
 (0)