Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-2007

Crash creating index when unable to connect

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • 1.5.3
    • 1.6.0
    • libmongoc
    • None

    Description

      mongoc_client_get_gridfs() may generate segfault internally.

      For example:

      #include <mongoc.h>
       
      int main() {
      	mongoc_client_t *client;
      	mongoc_gridfs_t *gridfs;
      	bson_error_t error;
       
      	mongoc_init();
       
      	client = mongoc_client_new("mongodb://INVALID-URI");
      	BSON_ASSERT(client);
      	gridfs = mongoc_client_get_gridfs(client, "test-gridfs", 0, &error);
      	BSON_ASSERT(!gridfs);
       
      	mongoc_client_destroy(client);
      	mongoc_cleanup();
      	return 0;
      }
      

      Output:

      $ ./a.out
      Segmentation fault
      

      Valgrind's output:

      ==10844== Invalid read of size 8
      ==10844==    at 0x4E4D144: mongoc_cluster_run_command_monitored (mongoc-cluster.c:362)
      ==10844==    by 0x4E521BA: mongoc_collection_create_index_with_opts (mongoc-collection.c:1325)
      ==10844==    by 0x4E528AF: mongoc_collection_create_index (mongoc-collection.c:1155)
      ==10844==    by 0x4E5CCBE: _mongoc_gridfs_ensure_index (mongoc-gridfs.c:66)
      ==10844==    by 0x4E5CCBE: _mongoc_gridfs_new (mongoc-gridfs.c:133)
      ==10844==    by 0x400887: main (libmongoc5.c:12)
      ==10844==  Address 0x8 is not stack'd, malloc'd or (recently) free'd
      ==10844==
      ==10844==
      ==10844== Process terminating with default action of signal 11 (SIGSEGV)
      ==10844==  Access not within mapped region at address 0x8
      ==10844==    at 0x4E4D144: mongoc_cluster_run_command_monitored (mongoc-cluster.c:362)
      ==10844==    by 0x4E521BA: mongoc_collection_create_index_with_opts (mongoc-collection.c:1325)
      ==10844==    by 0x4E528AF: mongoc_collection_create_index (mongoc-collection.c:1155)
      ==10844==    by 0x4E5CCBE: _mongoc_gridfs_ensure_index (mongoc-gridfs.c:66)
      ==10844==    by 0x4E5CCBE: _mongoc_gridfs_new (mongoc-gridfs.c:133)
      ==10844==    by 0x400887: main (libmongoc5.c:12)
      

      Attachments

        Issue Links

          Activity

            People

              jesse@mongodb.com A. Jesse Jiryu Davis
              neoxic Arseny Vakhrushev
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: