Skip to content

Commit

Permalink
Add note on NUL terminator check for safety
Browse files Browse the repository at this point in the history
1. Add note on checking for NUL terminator explicitly and adding it if not present. This is done for safety.
  • Loading branch information
Alois Mbutura authored Dec 9, 2017
1 parent e09abc8 commit a260c7a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions firmware/components/ble_api/ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit a260c7a

Please sign in to comment.