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

unchecked malloc and realloc in gridfs_store_stream

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None
    • latest in git

    Description

      In gridfs_store_stream, there are unchecked malloc and realloc calls.
      if any of those fail with NULL, the following code will dereference NULL,
      probably provoking a segfault:

      if ( to_write < gfs->chunk_len ) {
      if( gfs->pending_data )

      { gfs->pending_data = (char *)realloc((void *)gfs->pending_data, gfs->pending_len + to_write); memcpy( gfs->pending_data + gfs->pending_len, data, length ); }

      else if (to_write > 0)

      { gfs->pending_data = (char *)malloc(to_write); memcpy( gfs->pending_data, data, length ); }

      gfs->pending_len += length;
      } else {

      I didn't try to fix it because I suspect the function is incomplete.
      Its return type is "bson", yet there is no return statement.

      Attachments

        Activity

          People

            kbanker Kyle Banker
            meyering Jim Meyering
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: