mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 01:21:03 +01:00
SERVER-39375 fix trafficRecordingFileToBSONArr
The convertTrafficRecordingToBSON function in the shell calls trafficRecordingFileToBSONArr. When called on a non-existant file, this leaves inputFd <0, which causes crashes when ::close is invoked. The fix is to move the guard which cleans up the file until after the check that it is valid
This commit is contained in:
parent
98e1865778
commit
8f7034ae18
@ -6,6 +6,10 @@
|
||||
const recordingFilePath = MongoRunner.toRealDir(recordingDir + "/" + recordingFile);
|
||||
const replayFilePath = MongoRunner.toRealDir(recordingDir + "/replay.txt");
|
||||
|
||||
assert.throws(function() {
|
||||
convertTrafficRecordingToBSON("notarealfileatall");
|
||||
});
|
||||
|
||||
// Create the recording directory if it does not already exist
|
||||
mkdir(recordingDir);
|
||||
|
||||
|
@ -212,12 +212,12 @@ BSONArray trafficRecordingFileToBSONArr(const std::string& inputFile) {
|
||||
auto inputFd = ::open(inputFile.c_str(), O_RDONLY);
|
||||
#endif
|
||||
|
||||
const auto guard = makeGuard([&] { ::close(inputFd); });
|
||||
|
||||
uassert(ErrorCodes::FileNotOpen,
|
||||
str::stream() << "Specified file does not exist (" << inputFile << ")",
|
||||
inputFd > 0);
|
||||
|
||||
const auto guard = makeGuard([&] { ::close(inputFd); });
|
||||
|
||||
auto buf = SharedBuffer::allocate(MaxMessageSizeBytes);
|
||||
while (auto packet = readPacket(buf.get(), inputFd)) {
|
||||
BSONObjBuilder bob(builder.subobjStart());
|
||||
|
Loading…
Reference in New Issue
Block a user