mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Fix invalid memory accesses when parsing bogus RadioTap
This commit is contained in:
@@ -152,6 +152,9 @@ RadioTapParser::RadioTapParser(const vector<uint8_t>& buffer)
|
||||
current_flags_ = 0;
|
||||
}
|
||||
else {
|
||||
if (TINS_UNLIKELY(buffer.size() < sizeof(RadioTapFlags))) {
|
||||
throw malformed_packet();
|
||||
}
|
||||
start_ = &*buffer.begin();
|
||||
end_ = start_ + buffer.size();
|
||||
load_current_flags();
|
||||
@@ -257,11 +260,11 @@ const uint8_t* RadioTapParser::find_options_start() const {
|
||||
// Skip fields before the flags one
|
||||
const RadioTapFlags* flags = get_flags_ptr();
|
||||
while (flags->ext == 1) {
|
||||
total_sz -= sizeof(RadioTapFlags);
|
||||
if (TINS_UNLIKELY(total_sz < sizeof(RadioTapFlags))) {
|
||||
throw malformed_packet();
|
||||
}
|
||||
++flags;
|
||||
total_sz -= sizeof(RadioTapFlags);
|
||||
}
|
||||
return reinterpret_cast<const uint8_t*>(flags) + sizeof(RadioTapFlags);
|
||||
}
|
||||
|
||||
@@ -626,6 +626,14 @@ TEST_F(RadioTapTest, RadioTapParsingUsingEmptyBuffer) {
|
||||
EXPECT_FALSE(parser.has_field(RadioTap::ANTENNA));
|
||||
}
|
||||
|
||||
TEST_F(RadioTapTest, RadioTapParsingUsingBogusBuffer) {
|
||||
vector<uint8_t> buffer;
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
buffer.push_back(0xff);
|
||||
}
|
||||
EXPECT_THROW(RadioTapParser parser(buffer), malformed_packet);
|
||||
}
|
||||
|
||||
TEST_F(RadioTapTest, RadioTapWritingEmptyBuffer) {
|
||||
vector<uint8_t> buffer;
|
||||
RadioTapWriter writer(buffer);
|
||||
|
||||
Reference in New Issue
Block a user