[SERVER-27298] Some argument parsing silently truncates at NUL bytes Created: 06/Dec/16  Updated: 06/Dec/17  Resolved: 22/Jun/17

Status: Closed
Project: Core Server
Component/s: Replication
Affects Version/s: None
Fix Version/s: 3.5.10

Type: Bug Priority: Major - P3
Reporter: Mathias Stearn Assignee: Ted Tuckman
Resolution: Done Votes: 0
Labels: neweng, platforms-interns-2017
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Platforms 2017-07-10
Participants:

 Description   

A few options in mongod_options.cpp (such as "replication.replSetName") call std::string.c_str() then passes the result to a function that takes a std::string. This appears to be unintentional, but has the impact of silently truncating the option at the first \0 byte. I don't think it is possible to pass embedded NUL bytes on the command line so it requires a config file. Example config file:

replication:
  replSetName: "Oh No\0!"

I see a few possible options:

  1. Remove the c_str() and start including the NUL byte. Maybe also add validation with allowed characters in replSet names.
  2. Error if there is a NUL byte.
  3. Decide this is intentional and add a comment explaining it. We should also look at arguments without a c_str() and decide if they should also truncate.
  4. Decide that no options in the config file should support NUL bytes and error in the main options parser logic.


 Comments   
Comment by Githook User [ 22/Jun/17 ]

Author:

{u'username': u'TedTuckman', u'name': u'Ted Tuckman', u'email': u'ted.tuckman@mongodb.com'}

Message: SERVER-27298 Options Parser now rejects null bytes in all cases
Branch: master
https://github.com/mongodb/mongo/commit/dba32749903786dce9ab45b7aaf6ae0fffef0501

Comment by Eric Milkie [ 06/Dec/16 ]

I vote number 4.

Generated at Thu Feb 08 04:14:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.