Skip to content

Commit 56e7b77

Browse files
Thalleykartben
authored andcommitted
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 <[email protected]>
1 parent 444e59e commit 56e7b77

File tree

1 file changed

+61
-0
lines changed
  • subsys/bluetooth/host

1 file changed

+61
-0
lines changed

subsys/bluetooth/host/adv.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <zephyr/bluetooth/bluetooth.h>
1212
#include <zephyr/bluetooth/hci.h>
1313
#include <zephyr/bluetooth/buf.h>
14+
#include <zephyr/sys/check.h>
1415

1516
#include "addr_internal.h"
1617
#include "hci_core.h"
@@ -1566,6 +1567,12 @@ int bt_le_ext_adv_create(const struct bt_le_adv_param *param,
15661567
return -EAGAIN;
15671568
}
15681569

1570+
CHECKIF(out_adv == NULL) {
1571+
LOG_DBG("out_adv is NULL");
1572+
1573+
return -EINVAL;
1574+
}
1575+
15691576
if (!valid_adv_ext_param(param)) {
15701577
return -EINVAL;
15711578
}
@@ -1591,6 +1598,12 @@ int bt_le_ext_adv_create(const struct bt_le_adv_param *param,
15911598
int bt_le_ext_adv_update_param(struct bt_le_ext_adv *adv,
15921599
const struct bt_le_adv_param *param)
15931600
{
1601+
CHECKIF(adv == NULL) {
1602+
LOG_DBG("adv is NULL");
1603+
1604+
return -EINVAL;
1605+
}
1606+
15941607
if (!valid_adv_ext_param(param)) {
15951608
return -EINVAL;
15961609
}
@@ -1625,6 +1638,12 @@ int bt_le_ext_adv_start(struct bt_le_ext_adv *adv,
16251638
struct bt_conn *conn = NULL;
16261639
int err;
16271640

1641+
CHECKIF(adv == NULL) {
1642+
LOG_DBG("adv is NULL");
1643+
1644+
return -EINVAL;
1645+
}
1646+
16281647
if (atomic_test_bit(adv->flags, BT_ADV_ENABLED)) {
16291648
return -EALREADY;
16301649
}
@@ -1682,6 +1701,12 @@ int bt_le_ext_adv_start(struct bt_le_ext_adv *adv,
16821701

16831702
int bt_le_ext_adv_stop(struct bt_le_ext_adv *adv)
16841703
{
1704+
CHECKIF(adv == NULL) {
1705+
LOG_DBG("adv is NULL");
1706+
1707+
return -EINVAL;
1708+
}
1709+
16851710
(void)bt_le_lim_adv_cancel_timeout(adv);
16861711

16871712
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,
17121737
{
17131738
bool ext_adv, scannable;
17141739

1740+
CHECKIF(adv == NULL) {
1741+
LOG_DBG("adv is NULL");
1742+
1743+
return -EINVAL;
1744+
}
1745+
17151746
ext_adv = atomic_test_bit(adv->flags, BT_ADV_EXT_ADV);
17161747
scannable = atomic_test_bit(adv->flags, BT_ADV_SCANNABLE);
17171748

@@ -1736,6 +1767,12 @@ int bt_le_ext_adv_delete(struct bt_le_ext_adv *adv)
17361767
return -ENOTSUP;
17371768
}
17381769

1770+
CHECKIF(adv == NULL) {
1771+
LOG_DBG("adv is NULL");
1772+
1773+
return -EINVAL;
1774+
}
1775+
17391776
/* Advertising set should be stopped first */
17401777
if (atomic_test_bit(adv->flags, BT_ADV_ENABLED)) {
17411778
return -EINVAL;
@@ -1815,6 +1852,12 @@ int bt_le_per_adv_set_param(struct bt_le_ext_adv *adv,
18151852
return -ENOTSUP;
18161853
}
18171854

1855+
CHECKIF(adv == NULL) {
1856+
LOG_DBG("adv is NULL");
1857+
1858+
return -EINVAL;
1859+
}
1860+
18181861
if (atomic_test_bit(adv->flags, BT_ADV_SCANNABLE)) {
18191862
return -EINVAL;
18201863
} 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,
18871930
return -ENOTSUP;
18881931
}
18891932

1933+
CHECKIF(adv == NULL) {
1934+
LOG_DBG("adv is NULL");
1935+
1936+
return -EINVAL;
1937+
}
1938+
18901939
if (!atomic_test_bit(adv->flags, BT_PER_ADV_PARAMS_SET)) {
18911940
return -EINVAL;
18921941
}
@@ -1922,6 +1971,12 @@ int bt_le_per_adv_set_subevent_data(const struct bt_le_ext_adv *adv, uint8_t num
19221971
return -ENOTSUP;
19231972
}
19241973

1974+
CHECKIF(adv == NULL) {
1975+
LOG_DBG("adv is NULL");
1976+
1977+
return -EINVAL;
1978+
}
1979+
19251980
for (size_t i = 0; i < num_subevents; i++) {
19261981
cmd_length += sizeof(struct bt_hci_cp_le_set_pawr_subevent_data_element);
19271982
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)
19632018
return -ENOTSUP;
19642019
}
19652020

2021+
CHECKIF(adv == NULL) {
2022+
LOG_DBG("adv is NULL");
2023+
2024+
return -EINVAL;
2025+
}
2026+
19662027
/* TODO: We could setup some default ext adv params if not already set*/
19672028
if (!atomic_test_bit(adv->flags, BT_PER_ADV_PARAMS_SET)) {
19682029
return -EINVAL;

0 commit comments

Comments
 (0)