unchecked malloc and realloc in gridfs_store_stream

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Environment:
      latest in git
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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.

            Assignee:
            Kyle Banker (Inactive)
            Reporter:
            Jim Meyering
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: