Detected by OSS-Fuzz. Also make sure that we don't try to parse
packets smaller than 12 bytes in the fuzzing target, those are
usually dropped earlier.
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- if (size > std::numeric_limits<uint16_t>::max()) {
+ if (size > std::numeric_limits<uint16_t>::max() || size < sizeof(dnsheader)) {
return 0;
}
uint16_t optionLen;
while (pos < packetSize && rdataRead < rdLen && getNextEDNSOption(&packet.at(pos), rdLen - rdataRead, optionCode, optionLen)) {
- if (optionLen > (rdLen - rdataRead)) {
+ if (optionLen > (rdLen - rdataRead - 4)) {
if (packetSize > pos) {
currentHash = burtle(reinterpret_cast<const unsigned char*>(&packet.at(pos)), packetSize - pos, currentHash);
}