[SERVER-29022] OpMsgRequest::getDatabase() should check type of _msg.body["$db"] before calling valueStringData() Created: 29/Apr/17  Updated: 30/Oct/23  Resolved: 05/May/17

Status: Closed
Project: Core Server
Component/s: Networking
Affects Version/s: None
Fix Version/s: 3.5.7

Type: Bug Priority: Major - P3
Reporter: Max Hirschhorn Assignee: Mathias Stearn
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
is related to SERVER-28508 Egress and mongod ingress network lay... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

db.runCommand({$db: 127});

Sprint: Repl 2017-05-08
Participants:
Linked BF Score: 0

 Description   

It is possible that the user's request specifies a type other than a string as the $db parameter, so checking the type is necessary to avoid performing an invalid memory access when using the returned StringData later on.

class OpMsgRequest final : public rpc::RequestInterface {
public:
    explicit OpMsgRequest(OpMsg msg) : _msg(std::move(msg)) {}
    StringData getDatabase() const override {
        if (auto db = _msg.body["$db"]) {
            return db.valueStringData();
        }
        return "admin";
    }



 Comments   
Comment by Githook User [ 05/May/17 ]

Author:

{u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

Message: SERVER-29022 Check type of $db in OpMsgRequest
Branch: master
https://github.com/mongodb/mongo/commit/ea6788f9c835a2bc9fd33a17fb12d5aef3b4b7f1

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