Bluetooth: services: Adds OTS name length checks
Adds name length checks. The OTS spec does not explicitely specifiy a maximum name length, but the maximum name length in the directory listing object shall be less or equal to 120 octets. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
5a90fcee3a
commit
cfe0849072
3 changed files with 17 additions and 3 deletions
|
@ -33,6 +33,9 @@ extern "C" {
|
|||
/** @brief Length of OTS object ID string (in bytes). */
|
||||
#define BT_OTS_OBJ_ID_STR_LEN 15
|
||||
|
||||
/** @brief Maximum object name length */
|
||||
#define BT_OTS_OBJ_MAX_NAME_LEN 120
|
||||
|
||||
/** @brief Type of an OTS object. */
|
||||
struct bt_ots_obj_type {
|
||||
union {
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include <bluetooth/uuid.h>
|
||||
#include <bluetooth/gatt.h>
|
||||
|
||||
#include <sys/check.h>
|
||||
|
||||
#include <bluetooth/services/ots.h>
|
||||
#include "ots_internal.h"
|
||||
#include "ots_obj_manager_internal.h"
|
||||
|
@ -167,6 +169,7 @@ int bt_ots_obj_add(struct bt_ots *ots,
|
|||
{
|
||||
int err;
|
||||
struct bt_gatt_ots_object *obj;
|
||||
size_t name_len;
|
||||
|
||||
if (IS_ENABLED(CONFIG_BT_OTS_DIR_LIST_OBJ) && ots->dir_list &&
|
||||
ots->dir_list->dir_list_obj->state.type != BT_GATT_OTS_OBJECT_IDLE_STATE) {
|
||||
|
@ -174,6 +177,13 @@ int bt_ots_obj_add(struct bt_ots *ots,
|
|||
return -EBUSY;
|
||||
}
|
||||
|
||||
name_len = strlen(obj_init->name);
|
||||
|
||||
CHECKIF(name_len == 0 || name_len > BT_OTS_OBJ_MAX_NAME_LEN) {
|
||||
LOG_DBG("Invalid name length %zu", name_len);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
err = bt_gatt_ots_obj_manager_obj_add(ots->obj_manager, &obj);
|
||||
if (err) {
|
||||
LOG_ERR("No space available in the object manager");
|
||||
|
|
|
@ -44,7 +44,7 @@ static void dir_list_object_encode(struct bt_gatt_ots_object *obj,
|
|||
|
||||
/* Name length */
|
||||
obj_name_len = strlen(obj->metadata.name);
|
||||
__ASSERT(obj_name_len > 0 && obj_name_len <= 120,
|
||||
__ASSERT(obj_name_len > 0 && obj_name_len <= BT_OTS_OBJ_MAX_NAME_LEN,
|
||||
"Dir list object len is incorrect %zu", len);
|
||||
net_buf_simple_add_u8(net_buf, obj_name_len);
|
||||
|
||||
|
@ -220,8 +220,9 @@ void bt_ots_dir_list_init(struct bt_ots_dir_list **dir_list, void *obj_manager)
|
|||
|
||||
__ASSERT(*dir_list, "Could not assign Directory Listing Object");
|
||||
|
||||
__ASSERT(strlen(dir_list_obj_name) < UINT8_MAX,
|
||||
"BT_OTS_DIR_LIST_OBJ_NAME shall be less than 255 octets");
|
||||
__ASSERT(strlen(dir_list_obj_name) <= BT_OTS_OBJ_MAX_NAME_LEN,
|
||||
"BT_OTS_DIR_LIST_OBJ_NAME shall be less than %u octets",
|
||||
BT_OTS_OBJ_MAX_NAME_LEN);
|
||||
|
||||
err = bt_gatt_ots_obj_manager_obj_add(obj_manager, &dir_list_obj);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue