[SERVER-1275] DBClientCursor may call strlen on uninitialized bytes Created: 21/Jun/10 Updated: 12/Jul/16 Resolved: 21/Jun/10 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Internal Client |
| Affects Version/s: | 1.5.3 |
| Fix Version/s: | 1.5.4 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Andrew Morrow (Inactive) | Assignee: | Eliot Horowitz (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Operating System: | ALL |
| Participants: |
| Description |
|
See http://github.com/mongodb/mongo/blob/master/client/dbclientcursor.cpp#L125 If qr->nReturned is zero, then qr->data() returns a pointer to uninitialized bytes, which is then passed to DBConnector::checkResponse at the above line. But the signature of DBConnector::checkResponse requires that this call convert its first argument to a temporary std::string: that requires a call to strlen on the provided pointer. In the case under discussion, that leads to a call to strlen on an uninitialized buffer. Either line 125 should be changed to correctly handle the case where nReturned is zero, and not attempt to construct a temporary std::string in that case, or DBConnector::checkResponse should be changed to take a const char* first argument, and then correctly handle the case where its second argument is zero. This shows up in valgrind like this: ==15773== Conditional jump or move depends on uninitialised value(s) |
| Comments |
| Comment by Andrew Morrow (Inactive) [ 21/Jun/10 ] |
|
Thanks Eliot - I noticed that in the checkin above that you fixed the next issue I was about to report: that checkResponse was a shadowed virtual function. This actually breaks the codebase where we are trying to integrate the mongo C++ client, which builds with the GCC flag -Woverloaded-virtual to catch exactly this sort of issue. Unfortunately, we can't currently compile the mongo headers because of these shadowed virtuals, and we are reluctant to dial down our warnings. Here are some other shadowed functions exposed in the client headers: ~/mongo.temp.install/include/mongo/client/dbclient.h:293: error: 'virtual bool mongo::DBClientWithCommands::auth(const std::string&, const std::string&, const std::string&, std::string&, bool)' was hidden These sorts of overloads are frequently buggy: maybe you should add -Woverloaded-virtual to your warning flags as well? |
| Comment by auto [ 21/Jun/10 ] |
|
Author: {'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}Message: fix bad result handling |