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

libbson truncates code_with_scope with embedded nulls in javascript

    • Type: Icon: New Feature New Feature
    • Resolution: Won't Fix
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.7.0
    • Affects Version/s: None
    • Component/s: libbson
    • None

      The spec for code_with_scope says that the javascript is a "string", which is allowed to have embedded nulls. However the API for bson_append_code_with_scope has no parameter for the javascript length, so computes it with strlen in bson.c line 963. This truncates any input with embedded nulls.

      In order to fully support the spec and pass the BSON Corpus tests, we need a new function:

      
      /**
       * bson_append_code_with_scope_and_length:
       * @bson: A bson_t.
       * @key: The key for the document.
       * @javascript: JavaScript code to be executed.
       * @scope: A bson_t containing the scope for @javascript.
       *
       * Appends a field of type BSON_TYPE_CODE to the BSON document
       * if @scope is NULL. Appends BSON_TYPE_CODEWSCOPE if @scope
       * is not NULL (even if it is an empty document). Unlike 
       * bson_append_code_with_scope, this function makes it possible
       * to embed literal NULL bytes in the Javascript text.
       *
       * Returns: true if successful; false if append would overflow max size.
       */
      BSON_API
      bool
      bson_append_code_with_scope_and_length (bson_t       *bson,
                                              const char   *key,
                                              int           key_length,
                                              const char   *javascript,
                                              int           js_length,
                                              const bson_t *scope);
      

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            david.golden@mongodb.com David Golden
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: