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
|
@ -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");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue