From a260c7a928a594bb2a4fb2421d08fff3fecb8270 Mon Sep 17 00:00:00 2001 From: Alois Mbutura Date: Sat, 9 Dec 2017 14:09:11 +0300 Subject: [PATCH] Add note on NUL terminator check for safety 1. Add note on checking for NUL terminator explicitly and adding it if not present. This is done for safety. --- firmware/components/ble_api/ble.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/components/ble_api/ble.c b/firmware/components/ble_api/ble.c index 1e1b1a9..d371ac7 100644 --- a/firmware/components/ble_api/ble.c +++ b/firmware/components/ble_api/ble.c @@ -1031,7 +1031,7 @@ static void bytestring_check_then_write(esp_attr_value_t* attribute, prepare_wri if(prepare_write_env->prepare_buf[(prepare_write_env->prepare_len)-1] != '\0') { - /*Byte array lacks NUL string terminator*/ + /*Safety check-Byte array lacks NUL string terminator*/ uint8_t* nul_terminated_buffer=(uint8_t*)malloc((prepare_write_env->prepare_len)+1); memcpy(nul_terminated_buffer, prepare_write_env->prepare_buf, prepare_write_env->prepare_len); nul_terminated_buffer[prepare_write_env->prepare_len] = '\0'; @@ -1082,7 +1082,7 @@ static void bytestring_check_then_write(esp_attr_value_t* attribute, prepare_wri } else { - /*Byte array contains NUL string terminator*/ + /*Safety check-Byte array contains NUL string terminator*/ invalid = simple_check_UTF8((char*)prepare_write_env->prepare_buf); if(!invalid) {