Skip to content

Commit 3f27034

Browse files
alexeyvohanumantmk
authored andcommitted
Fix access violation when error == NULL in mongoc_database_find_collections
Closes #161
1 parent 4e4d8a5 commit 3f27034

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/mongoc/mongoc-database.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@ mongoc_database_find_collections (mongoc_database_t *database,
762762
mongoc_read_prefs_t *read_prefs;
763763
bson_t cmd = BSON_INITIALIZER;
764764
bson_t child;
765+
bson_error_t lerror;
765766

766767
BSON_ASSERT (database);
767768

@@ -785,16 +786,17 @@ mongoc_database_find_collections (mongoc_database_t *database,
785786
if (_mongoc_cursor_cursorid_prime (cursor)) {
786787
/* intentionally empty */
787788
} else {
788-
if (mongoc_cursor_error (cursor, error)) {
789-
if (error->code == MONGOC_ERROR_QUERY_COMMAND_NOT_FOUND) {
789+
if (mongoc_cursor_error (cursor, &lerror)) {
790+
if (lerror.code == MONGOC_ERROR_QUERY_COMMAND_NOT_FOUND) {
790791
/* We are talking to a server that doesn' support listCollections. */
791792
/* clear out the error. */
792-
error->code = 0;
793-
error->domain = 0;
793+
memset (&lerror, 0, sizeof lerror);
794794
/* try again with using system.namespaces */
795795
mongoc_cursor_destroy (cursor);
796796
cursor = _mongoc_database_find_collections_legacy (
797797
database, filter, error);
798+
} else if (error) {
799+
memcpy (error, &lerror, sizeof *error);
798800
}
799801
} else {
800802
/* TODO: remove this branch for general release. Only relevant for RC */

0 commit comments

Comments
 (0)