BSON C-Extension: Remove dereference before null check

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • 1.9.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Here we're allocating memory for a new buffer, then attempting to call bson_buffer_set_max_size before performing a null check. At this point in this code path, the null check isn't necessary and should be done before we try to set the buffer's max_size.

      bson_buffer_t buffer = bson_buffer_new();
      bson_buffer_set_max_size(buffer, FIX2INT(max_size));
      if (buffer == NULL) {
          rb_raise(rb_eNoMemError, "failed to allocate memory in buffer.c");
      }
      

      Link:
      https://github.com/mongodb/mongo-ruby-driver/blob/master/ext/cbson/cbson.c#L618-L622

            Assignee:
            Brandon Black (Inactive)
            Reporter:
            Brandon Black (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: