uuid_to_le() returns one of the possible values from bt_uuid_len(). bt_uuid_len() returns "type / 8". type is a value between 0 and 128, but could be something else depending on the validity of the UUID that's parsed. So an invalid value of type between 128 and 256 would trigger an overrun. Add a check to make sure that an invalid type isn't used to calculate the length. Error: OVERRUN (CWE-119): [#def6] [important] bluez-5.77/src/shared/gatt-db.c:612:2: assignment: Assigning: "len" = "uuid_to_le(uuid, value)". The value of "len" is now between 0 and 31 (inclusive). bluez-5.77/src/shared/gatt-db.c:614:2: overrun-buffer-arg: Overrunning array "value" of 16 bytes by passing it to a function which accesses it at byte offset 30 using argument "len" (which evaluates to 31). 612| len = uuid_to_le(uuid, value); 613| 614|-> service->attributes[0] = new_attribute(service, handle, type, value, 615| len); 616| if (!service->attributes[0]) { --- src/shared/gatt-db.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c index b35763410d17..cd0eba6bf1d0 100644 --- a/src/shared/gatt-db.c +++ b/src/shared/gatt-db.c @@ -560,9 +560,14 @@ static int uuid_to_le(const bt_uuid_t *uuid, uint8_t *dst) return bt_uuid_len(uuid); } - bt_uuid_to_uuid128(uuid, &uuid128); - bswap_128(&uuid128.value.u128, dst); - return bt_uuid_len(&uuid128); + if (uuid->type == BT_UUID32 || + uuid->type == BT_UUID128) { + bt_uuid_to_uuid128(uuid, &uuid128); + bswap_128(&uuid128.value.u128, dst); + return bt_uuid_len(&uuid128); + } + + return 0; } static bool le_to_uuid(const uint8_t *src, size_t len, bt_uuid_t *uuid) -- 2.45.2