[CDRIVER-1129] Silent failure parsing hostnames longer than HOST_NAME_MAX Created: 21/Feb/16  Updated: 07/Jun/17  Resolved: 08/Sep/16

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: 1.3.3
Fix Version/s: 1.5.0

Type: Bug Priority: Major - P3
Reporter: David Feurle Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux / Ubuntu


Attachments: File tst_mongouri.cpp    
Issue Links:
Related
related to CDRIVER-2044 Max URI set to only 64 chars Closed

 Description   

mongoc_uri_parse_hostname lowercases hostnames (CDRIVER-536) but doesn't NULL-terminate hostnames that exceed the platform's HOST_NAME_MAX. Original reporter used a platform where HOST_NAME_MAX is 64, on my Mac it's 255. Regardless, a longer hostname in the input results in an unterminated string in the mongoc_uri_t host list.



 Comments   
Comment by Githook User [ 08/Sep/16 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-1129 error if hostname too long
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/35adb389e54bf37bfaac416a1bd5afe5f6a0c92d

Comment by Julien BENOIT [ 07/Sep/16 ]

Thanks for your help.

@david This is what I did, and by the way it make the name more understandable.

Comment by A. Jesse Jiryu Davis [ 06/Sep/16 ]

david@firehome.de thanks for providing such effective help. =)

Comment by David Feurle [ 06/Sep/16 ]

@jesse nice work analyzing this! Thanks!

Comment by David Feurle [ 06/Sep/16 ]

@julien as a workaround you could add a shorter alias to your Hosts file.

Comment by David Feurle [ 06/Sep/16 ]

maybe it is an operating system / compile specific error? I'm using gcc 5.4 on ubuntu 16.04

Comment by David Feurle [ 06/Sep/16 ]

I'm a c++ programmer, I only have attached c++ code. Meanwhile I have set up a container with said test code. The error is still reproducible with v1.4. I can give you a limited shell access to the container so you could see for yourselve.

Comment by A. Jesse Jiryu Davis [ 06/Sep/16 ]

Thanks David, the C source code for a program I can run that reproduces the error would be ideal.

Comment by David Feurle [ 06/Sep/16 ]

It was really easy to reproduce -> do you want me to reproduce it and send you a debugable binary? Which os do you use? Could you set up a ubuntu 16.04 container?
Otherwise I could provide you access to a machine with all the stuff already installed.

Comment by A. Jesse Jiryu Davis [ 06/Sep/16 ]

Reopened, we'll see if we can reproduce the issue.

Comment by Julien BENOIT [ 06/Sep/16 ]

Hi,

I encounter pretty much the same problem. however, it was not directly with the mongo C driver, but through a PHP extension.

https://github.com/mongodb/mongo-php-driver/issues/387

I opened issue before I stumbled upon this ticket which makes me think it could be caused by the C driver.

The URI parsed incorrectly is : `internal-mongodb-elb-internal-1111111111.eu-west-1.elb.amazonaws.com`.

You can get full details in the ticket on PHP extension Github.

Thank you for your assistance.

Feel free to ask any questions.

Julien BENOIT.

P.S : I did not find out to reopen this ticket. I think since I am not the author, I can't

Comment by A. Jesse Jiryu Davis [ 20/Mar/16 ]

Hi, I'm not a C++ user so I wrote a test in C, parsing your example URI works as expected:

static void
test_mongoc_uri_long (void)
{
   mongoc_uri_t *uri;
 
   uri = mongoc_uri_new (
      "mongodb://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
      "@db-d8ccdb46-96d5-48f8-9367-7b443a3acd65.mdb001uans1.clouduser.bicadmin.com:30000/"
      "?maxIdleTimeMs=240000&replicaSet=shared-env-prod-1-noshard-replset-1"
      "&w=majority&readpreference=primary");
 
   assert (uri);
   assert (!strcmp (
      mongoc_uri_get_username (uri),
      "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
   assert (!strcmp (
      mongoc_uri_get_password (uri),
      "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"));
   assert (!strcmp (
      mongoc_uri_get_hosts (uri)->host_and_port,
      "db-d8ccdb46-96d5-48f8-9367-7b443a3acd65.mdb001uans1.clouduser.bicadmin.com:30000"));
   assert (!strcmp (
      mongoc_uri_get_hosts (uri)->host,
      "db-d8ccdb46-96d5-48f8-9367-7b443a3acd65.mdb001uans1.clouduser.bicadmin.com"));
 
   mongoc_uri_destroy (uri);
}

If your issue persists, please feel free to reopen this issue with more details about what's going wrong. In particular, if the parsed "host" or "host_and_port" in your test don't have the values you expect, then what are their actual values?

Comment by A. Jesse Jiryu Davis [ 21/Feb/16 ]

Interesting, thanks for the report!

Generated at Wed Feb 07 21:11:39 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.