From 639880bae58de1b4d95c577675d4860170dcdda9 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Mon, 16 Dec 2024 23:14:43 +0100 Subject: [PATCH] gatt-service/device_information_service_server: check NULL strings --- .../device_information_service_server.c | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/src/ble/gatt-service/device_information_service_server.c b/src/ble/gatt-service/device_information_service_server.c index cf2838239..a1c26c4dd 100644 --- a/src/ble/gatt-service/device_information_service_server.c +++ b/src/ble/gatt-service/device_information_service_server.c @@ -246,33 +246,32 @@ void device_information_service_server_set_udi_for_medical_devices(const char * // cppcheck-suppress objectIndex - bytes_copied = btstack_strcpy((char *) &data[pos], DEVICE_INFORMATION_MAX_STRING_LEN, label); - pos += bytes_copied; - if (bytes_copied > 0){ - data[0] |= (1 << UDI_FOR_MEDICAL_DEVICES_BITMASK_LABEL); - } + if (label != NULL){ + bytes_copied = btstack_strcpy((char *) &data[pos], DEVICE_INFORMATION_MAX_STRING_LEN, label); + pos += bytes_copied; + data[0] |= (1 << UDI_FOR_MEDICAL_DEVICES_BITMASK_LABEL); + } - // cppcheck-suppress objectIndex - bytes_copied = btstack_strcpy((char *) &data[pos], DEVICE_INFORMATION_MAX_STRING_LEN, device_id); - pos += bytes_copied; - if (bytes_copied > 0){ - data[0] |= (1 << UDI_FOR_MEDICAL_DEVICES_BITMASK_DEVICE_ID); - } + if (device_id != NULL){ + // cppcheck-suppress objectIndex + bytes_copied = btstack_strcpy((char *) &data[pos], DEVICE_INFORMATION_MAX_STRING_LEN, device_id); + pos += bytes_copied; + data[0] |= (1 << UDI_FOR_MEDICAL_DEVICES_BITMASK_DEVICE_ID); + } - // cppcheck-suppress objectIndex - bytes_copied = btstack_strcpy((char *) &data[pos], DEVICE_INFORMATION_MAX_STRING_LEN, issuer); - pos += bytes_copied; - if (bytes_copied > 0){ - data[0] |= (1 << UDI_FOR_MEDICAL_DEVICES_BITMASK_ISSUER); - } - - // cppcheck-suppress objectIndex - bytes_copied = btstack_strcpy((char *) &data[pos], DEVICE_INFORMATION_MAX_STRING_LEN, authority); - pos += bytes_copied; - if (bytes_copied > 0){ - data[0] |= (1 << UDI_FOR_MEDICAL_DEVICES_BITMASK_AUTHORITY); - } + if (issuer != NULL) { + // cppcheck-suppress objectIndex + bytes_copied = btstack_strcpy((char *) &data[pos], DEVICE_INFORMATION_MAX_STRING_LEN, issuer); + pos += bytes_copied; + data[0] |= (1 << UDI_FOR_MEDICAL_DEVICES_BITMASK_ISSUER); + } + if (authority != NULL){ + // cppcheck-suppress objectIndex + bytes_copied = btstack_strcpy((char *) &data[pos], DEVICE_INFORMATION_MAX_STRING_LEN, authority); + pos += bytes_copied; + data[0] |= (1 << UDI_FOR_MEDICAL_DEVICES_BITMASK_AUTHORITY); + } device_information_fields[UDI_FOR_MEDICAL_DEVICES].len = pos; }