Bluetooth: Host: Add adv == NULL checks in adv.c

Added null checks for adv pointer in the extended and
periodic advertising functions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2024-12-03 14:58:51 +01:00 committed by Benjamin Cabé
commit 56e7b7708e

View file

@ -11,6 +11,7 @@
#include <zephyr/bluetooth/bluetooth.h> #include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/hci.h> #include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/buf.h> #include <zephyr/bluetooth/buf.h>
#include <zephyr/sys/check.h>
#include "addr_internal.h" #include "addr_internal.h"
#include "hci_core.h" #include "hci_core.h"
@ -1566,6 +1567,12 @@ int bt_le_ext_adv_create(const struct bt_le_adv_param *param,
return -EAGAIN; return -EAGAIN;
} }
CHECKIF(out_adv == NULL) {
LOG_DBG("out_adv is NULL");
return -EINVAL;
}
if (!valid_adv_ext_param(param)) { if (!valid_adv_ext_param(param)) {
return -EINVAL; return -EINVAL;
} }
@ -1591,6 +1598,12 @@ int bt_le_ext_adv_create(const struct bt_le_adv_param *param,
int bt_le_ext_adv_update_param(struct bt_le_ext_adv *adv, int bt_le_ext_adv_update_param(struct bt_le_ext_adv *adv,
const struct bt_le_adv_param *param) const struct bt_le_adv_param *param)
{ {
CHECKIF(adv == NULL) {
LOG_DBG("adv is NULL");
return -EINVAL;
}
if (!valid_adv_ext_param(param)) { if (!valid_adv_ext_param(param)) {
return -EINVAL; return -EINVAL;
} }
@ -1625,6 +1638,12 @@ int bt_le_ext_adv_start(struct bt_le_ext_adv *adv,
struct bt_conn *conn = NULL; struct bt_conn *conn = NULL;
int err; int err;
CHECKIF(adv == NULL) {
LOG_DBG("adv is NULL");
return -EINVAL;
}
if (atomic_test_bit(adv->flags, BT_ADV_ENABLED)) { if (atomic_test_bit(adv->flags, BT_ADV_ENABLED)) {
return -EALREADY; return -EALREADY;
} }
@ -1682,6 +1701,12 @@ int bt_le_ext_adv_start(struct bt_le_ext_adv *adv,
int bt_le_ext_adv_stop(struct bt_le_ext_adv *adv) int bt_le_ext_adv_stop(struct bt_le_ext_adv *adv)
{ {
CHECKIF(adv == NULL) {
LOG_DBG("adv is NULL");
return -EINVAL;
}
(void)bt_le_lim_adv_cancel_timeout(adv); (void)bt_le_lim_adv_cancel_timeout(adv);
atomic_clear_bit(adv->flags, BT_ADV_PERSIST); atomic_clear_bit(adv->flags, BT_ADV_PERSIST);
@ -1712,6 +1737,12 @@ int bt_le_ext_adv_set_data(struct bt_le_ext_adv *adv,
{ {
bool ext_adv, scannable; bool ext_adv, scannable;
CHECKIF(adv == NULL) {
LOG_DBG("adv is NULL");
return -EINVAL;
}
ext_adv = atomic_test_bit(adv->flags, BT_ADV_EXT_ADV); ext_adv = atomic_test_bit(adv->flags, BT_ADV_EXT_ADV);
scannable = atomic_test_bit(adv->flags, BT_ADV_SCANNABLE); scannable = atomic_test_bit(adv->flags, BT_ADV_SCANNABLE);
@ -1736,6 +1767,12 @@ int bt_le_ext_adv_delete(struct bt_le_ext_adv *adv)
return -ENOTSUP; return -ENOTSUP;
} }
CHECKIF(adv == NULL) {
LOG_DBG("adv is NULL");
return -EINVAL;
}
/* Advertising set should be stopped first */ /* Advertising set should be stopped first */
if (atomic_test_bit(adv->flags, BT_ADV_ENABLED)) { if (atomic_test_bit(adv->flags, BT_ADV_ENABLED)) {
return -EINVAL; return -EINVAL;
@ -1815,6 +1852,12 @@ int bt_le_per_adv_set_param(struct bt_le_ext_adv *adv,
return -ENOTSUP; return -ENOTSUP;
} }
CHECKIF(adv == NULL) {
LOG_DBG("adv is NULL");
return -EINVAL;
}
if (atomic_test_bit(adv->flags, BT_ADV_SCANNABLE)) { if (atomic_test_bit(adv->flags, BT_ADV_SCANNABLE)) {
return -EINVAL; return -EINVAL;
} else if (atomic_test_bit(adv->flags, BT_ADV_CONNECTABLE)) { } else if (atomic_test_bit(adv->flags, BT_ADV_CONNECTABLE)) {
@ -1887,6 +1930,12 @@ int bt_le_per_adv_set_data(const struct bt_le_ext_adv *adv,
return -ENOTSUP; return -ENOTSUP;
} }
CHECKIF(adv == NULL) {
LOG_DBG("adv is NULL");
return -EINVAL;
}
if (!atomic_test_bit(adv->flags, BT_PER_ADV_PARAMS_SET)) { if (!atomic_test_bit(adv->flags, BT_PER_ADV_PARAMS_SET)) {
return -EINVAL; return -EINVAL;
} }
@ -1922,6 +1971,12 @@ int bt_le_per_adv_set_subevent_data(const struct bt_le_ext_adv *adv, uint8_t num
return -ENOTSUP; return -ENOTSUP;
} }
CHECKIF(adv == NULL) {
LOG_DBG("adv is NULL");
return -EINVAL;
}
for (size_t i = 0; i < num_subevents; i++) { for (size_t i = 0; i < num_subevents; i++) {
cmd_length += sizeof(struct bt_hci_cp_le_set_pawr_subevent_data_element); cmd_length += sizeof(struct bt_hci_cp_le_set_pawr_subevent_data_element);
cmd_length += params[i].data->len; cmd_length += params[i].data->len;
@ -1963,6 +2018,12 @@ static int bt_le_per_adv_enable(struct bt_le_ext_adv *adv, bool enable)
return -ENOTSUP; return -ENOTSUP;
} }
CHECKIF(adv == NULL) {
LOG_DBG("adv is NULL");
return -EINVAL;
}
/* TODO: We could setup some default ext adv params if not already set*/ /* TODO: We could setup some default ext adv params if not already set*/
if (!atomic_test_bit(adv->flags, BT_PER_ADV_PARAMS_SET)) { if (!atomic_test_bit(adv->flags, BT_PER_ADV_PARAMS_SET)) {
return -EINVAL; return -EINVAL;