Skip to content

Commit 62b8080

Browse files
authored
Update buffer position when returning kIgnored (#1760)
Summary: This PR removes the frame's contents from the buffer in the case we return `kIgnored` when the frame is a type (opcode) we do not parse. When running the BPF test we noticed that the program would stall when the parser encountered a frame with an opcode it does not support. This was due to to the parser returning `kIgnored` to `ParseFramesLoop` and it not moving the buffer forward before calling `ParseFrame` again. This change will update the buffer position before returning `kIgnored` to `ParseFramesLoop` so that the remaining frames in the buffer can be parsed. Related issues: #640 Type of change: /kind bug Test Plan: Modified the existing test checking for the unsupported opcode type. Signed-off-by: Kartik Pattaswamy <kpattaswamy@pixielabs.ai>
1 parent e6bfab7 commit 62b8080

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/stirling/source_connectors/socket_tracer/protocols/mongodb/parse.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ ParseState ParseFrame(message_type_t type, std::string_view* buf, Frame* frame,
6464
return ParseState::kInvalid;
6565
}
6666

67-
// Parser will ignore Op Codes that have been deprecated/removed from version 5.0 onwards.
68-
if (!(frame_type == Type::kOPMsg || frame_type == Type::kOPCompressed ||
69-
frame_type == Type::kReserved)) {
67+
// Parser will ignore Op Codes that have been deprecated/removed from version 5.0 onwards as well
68+
// as kOPCompressed and kReserved which are not supported by the parser yet.
69+
if (frame_type != Type::kOPMsg) {
70+
buf->remove_prefix(frame->length);
7071
return ParseState::kIgnored;
7172
}
7273

src/stirling/source_connectors/socket_tracer/protocols/mongodb/parse_test.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ TEST_F(MongoDBParserTest, ParseFrameWhenUnsupportedType) {
391391
ParseState state = ParseFrame(message_type_t::kRequest, &frame_view, &frame, &state_order);
392392

393393
EXPECT_EQ(state, ParseState::kIgnored);
394+
EXPECT_EQ(frame_view.length(), 0);
394395
}
395396

396397
TEST_F(MongoDBParserTest, ParseFrameInvalidFlagBits) {

0 commit comments

Comments
 (0)