Skip to content

Make RadioTapParser::skip_to_field check for end of buffer #296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/utils/radiotap_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ bool RadioTapParser::skip_to_field(RadioTap::PresentFlags flag) {
}

bool RadioTapParser::has_fields() const {
return current_bit_ != MAX_RADIOTAP_FIELD;
return current_bit_ != MAX_RADIOTAP_FIELD && current_ptr_ < end_;
}

bool RadioTapParser::has_field(RadioTap::PresentFlags flag) const {
Expand Down
57 changes: 56 additions & 1 deletion tests/src/radiotap_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RadioTapTest : public testing::Test {
static const uint8_t expected_packet[], expected_packet1[],
expected_packet2[], expected_packet3[],
expected_packet4[], expected_packet5[],
expected_packet6[];
expected_packet6[], expected_packet7[];
};

const uint8_t RadioTapTest::expected_packet[] = {
Expand Down Expand Up @@ -324,6 +324,57 @@ const uint8_t RadioTapTest::expected_packet6[] = {
164, 143, 87, 89, 97, 79, 145, 16, 48, 248, 198, 140, 48
};

const uint8_t RadioTapTest::expected_packet7[] = {
0, 255, 255, 0, 0, 240, 96, 235, 105, 143, 60, 180, 134, 221, 96,
0, 0, 0, 2, 164, 17, 64, 50, 73, 237, 197, 18, 75, 232, 197, 18,
72, 232, 197, 18, 72, 232, 71, 50, 73, 237, 125, 18, 75, 249, 195,
18, 72, 232, 197, 18, 239, 232, 197, 169, 236, 43, 206, 48, 166, 9,
84, 151, 88, 20, 229, 233, 39, 55, 108, 16, 104, 206, 107, 0, 53,
186, 70, 2, 164, 18, 0, 44, 150, 132, 3, 0, 1, 0, 0, 0, 6, 0, 1,
12, 67, 79, 56, 48, 49, 77, 49, 56, 48, 49, 57, 49, 13, 97, 122,
99, 111, 114, 114, 101, 99, 116, 105, 111, 110, 115, 5, 108, 111,
99, 97, 108, 0, 0, 6, 0, 1, 0, 0, 6, 0, 1, 0, 1, 81, 128, 0, 64, 1,
97, 12, 114, 111, 111, 116, 45, 115, 101, 114, 118, 101, 114, 115,
3, 110, 101, 116, 0, 5, 110, 115, 116, 108, 100, 12, 118, 101, 114,
105, 115, 105, 103, 110, 45, 103, 114, 115, 3, 99, 111, 109, 0,
120, 42, 86, 53, 0, 0, 7, 8, 0, 0, 3, 132, 0, 9, 58, 128, 0, 1, 81,
128, 5, 108, 111, 97, 110, 115, 0, 0, 47, 0, 1, 0, 1, 81, 128, 0,
15, 5, 108, 111, 99, 117, 115, 0, 0, 6, 32, 0, 0, 0, 0, 19, 0, 0,
47, 0, 1, 0, 1, 81, 128, 0, 14, 3, 97, 97, 97, 0, 0, 7, 26, 0, 0,
0, 0, 3, 128, 0, 0, 46, 0, 1, 0, 1, 81, 128, 0, 147, 0, 6, 8, 0, 0,
1, 81, 128, 87, 17, 30, 16, 87, 3, 225, 0, 236, 199, 0, 23, 89,
103, 40, 110, 160, 29, 93, 75, 23, 152, 78, 76, 255, 197, 241, 39,
189, 75, 31, 226, 166, 224, 55, 9, 100, 96, 27, 180, 130, 25, 199,
101, 176, 122, 115, 169, 75, 199, 174, 203, 181, 165, 16, 159, 111,
84, 166, 162, 242, 43, 255, 148, 16, 118, 212, 144, 118, 67, 113,
59, 31, 224, 181, 103, 41, 238, 3, 174, 153, 106, 80, 171, 124,
162, 186, 167, 108, 66, 140, 244, 97, 170, 127, 170, 252, 124, 139,
246, 150, 166, 208, 191, 15, 64, 250, 217, 195, 6, 39, 246, 71,
204, 248, 143, 71, 121, 44, 149, 98, 145, 203, 102, 74, 220, 240,
180, 8, 218, 171, 76, 194, 62, 241, 85, 94, 72, 28, 192, 125, 0,
46, 0, 30, 0, 1, 81, 128, 0, 147, 0, 47, 8, 1, 0, 1, 81, 128, 87,
17, 30, 16, 87, 3, 225, 0, 236, 199, 0, 159, 85, 2, 138, 56, 31,
91, 69, 9, 81, 254, 59, 65, 14, 76, 208, 107, 158, 159, 118, 92,
38, 52, 210, 139, 201, 40, 32, 135, 48, 252, 254, 64, 135, 97, 24,
253, 193, 114, 103, 214, 39, 14, 218, 50, 22, 60, 15, 208, 85, 152,
119, 21, 169, 236, 43, 206, 48, 166, 9, 84, 151, 88, 20, 229, 233,
39, 55, 108, 83, 104, 206, 107, 253, 252, 203, 24, 90, 216, 48,
191, 44, 38, 161, 228, 97, 84, 197, 138, 7, 206, 54, 244, 52, 153,
26, 232, 221, 182, 130, 29, 57, 193, 218, 124, 99, 68, 78, 161,
113, 120, 4, 155, 62, 94, 21, 89, 212, 33, 122, 42, 72, 5, 42, 172,
87, 70, 122, 0, 0, 46, 0, 1, 0, 1, 81, 128, 0, 147, 0, 47, 8, 0, 0,
1, 81, 128, 87, 17, 30, 16, 87, 3, 225, 0, 236, 199, 0, 131, 10,
126, 206, 35, 167, 184, 76, 112, 237, 170, 253, 123, 131, 162, 186,
243, 100, 237, 217, 17, 187, 90, 115, 28, 62, 89, 112, 69, 16, 227,
159, 162, 42, 212, 216, 246, 149, 118, 20, 105, 70, 196, 64, 48,
65, 216, 187, 25, 142, 138, 171, 229, 5, 251, 167, 181, 93, 62, 78,
204, 130, 147, 131, 168, 13, 120, 116, 115, 115, 107, 98, 53, 113,
111, 110, 56, 115, 110, 9, 95, 107, 101, 114, 98, 101, 114, 111,
115, 4, 95, 116, 99, 243, 21, 33, 14, 178, 86, 218, 241, 92, 120,
80, 120, 138, 155, 39, 74, 89, 32, 154, 143, 135, 103, 206, 121,
227, 234
};

TEST_F(RadioTapTest, DefaultConstructor) {
RadioTap radio;
EXPECT_TRUE((radio.flags() & RadioTap::FCS) != 0);
Expand Down Expand Up @@ -437,6 +488,10 @@ TEST_F(RadioTapTest, ConstructorFromBuffer5) {
EXPECT_EQ(0x05, radio.mcs().mcs);
}

TEST_F(RadioTapTest, ConstructorFromBuffer6) {
EXPECT_THROW(RadioTap(expected_packet7, sizeof(expected_packet7)), malformed_packet);
}

TEST_F(RadioTapTest, Serialize) {
RadioTap radio(expected_packet, sizeof(expected_packet));
RadioTap::serialization_type buffer = radio.serialize();
Expand Down