Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-612

BSON C-Extension: Remove dereference before null check

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.9.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      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@10gen.com Brandon Black
            Reporter:
            brandon.black@10gen.com Brandon Black
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: