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

mongoc_uri_parse_database() may overlap with URI host component

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.7.0
    • Affects Version/s: 1.5.0
    • Component/s: libmongoc
    • None

      In PHPLIB-174, a user failed to escape the Unix domain socket path in their connection URI and received an odd exception message when database authentication failed. While reading the server logs, I realized that libmongoc was still connecting via a Unix domain socket, despite the socket path inadvertently getting picked up as uri->database in mongoc-uri.c.

      I added some string dumping to mongoc_uri_parse_database() and mongoc_uri_append_host() and determined the following:

      URI: mongodb://foo:bar@/tmp/mongodb-27017.sock/admin
      HOST: /tmp/mongodb-27017.sock
      DATABASE: tmp/mongodb-27017.sock:27017/
      

      Although Unix domain sockets do need to be escaped per the Connection String Specification, I found it odd that libmongoc was able to parse the host properly, but failed to parse the database. Since the order of URI components is clearly defined (e.g. credentials, host list, database, query string), database parsing should start after the host list to ensure that component parsing never overlaps.

            Assignee:
            bjori Hannes Magnusson
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: