From ecf98ce012251866bb09f9c78663660844675fa1 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 25 Feb 2020 10:47:24 +0100 Subject: [PATCH] ad_parser: avoid out-of-bounds read in ad_data_contains_uuid16/128 helpers --- src/ad_parser.c | 10 ++++------ test/fuzz/fuzz_ad_parser.c | 12 ++++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 test/fuzz/fuzz_ad_parser.c diff --git a/src/ad_parser.c b/src/ad_parser.c index 4efc68845..1778bec79 100644 --- a/src/ad_parser.c +++ b/src/ad_parser.c @@ -109,7 +109,7 @@ bool ad_data_contains_uuid16(uint8_t ad_len, const uint8_t * ad_data, uint16_t u switch (data_type){ case BLUETOOTH_DATA_TYPE_INCOMPLETE_LIST_OF_16_BIT_SERVICE_CLASS_UUIDS: case BLUETOOTH_DATA_TYPE_COMPLETE_LIST_OF_16_BIT_SERVICE_CLASS_UUIDS: - for (i=0; i +#include + +#include "ad_parser.h" + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + // ad parser uses uint88_t length + if (size > 255) return 0; + // test ad iterator by calling simple function that uses it + ad_data_contains_uuid16(size, data, 0xffff); + return 0; +}