Skip to content

Commit a01a619

Browse files
joerchancarlescufi
authored andcommitted
Bluetooth: SMP: Check return value of bt_rand
Add check of bt_rand return value and do not proceed in case of error. Signed-off-by: Joakim Andersson <[email protected]>
1 parent d138790 commit a01a619

File tree

1 file changed

+11
-3
lines changed
  • subsys/bluetooth/host

1 file changed

+11
-3
lines changed

subsys/bluetooth/host/smp.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,10 @@ static void smp_br_distribute_keys(struct bt_smp_br *smp)
12511251

12521252
info = net_buf_add(buf, sizeof(*info));
12531253

1254-
bt_rand(info->csrk, sizeof(info->csrk));
1254+
if (bt_rand(info->csrk, sizeof(info->csrk))) {
1255+
BT_ERR("Unable to get random bytes");
1256+
return;
1257+
}
12551258

12561259
if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) {
12571260
bt_keys_add_type(keys, BT_KEYS_LOCAL_CSRK);
@@ -2048,7 +2051,10 @@ static void legacy_distribute_keys(struct bt_smp *smp)
20482051
uint8_t ediv[2];
20492052
} rand;
20502053

2051-
bt_rand((void *)&rand, sizeof(rand));
2054+
if (bt_rand((void *)&rand, sizeof(rand))) {
2055+
BT_ERR("Unable to get random bytes");
2056+
return;
2057+
}
20522058

20532059
buf = smp_create_pdu(smp, BT_SMP_CMD_ENCRYPT_INFO,
20542060
sizeof(*info));
@@ -2158,7 +2164,9 @@ static uint8_t bt_smp_distribute_keys(struct bt_smp *smp)
21582164

21592165
info = net_buf_add(buf, sizeof(*info));
21602166

2161-
bt_rand(info->csrk, sizeof(info->csrk));
2167+
if (bt_rand(info->csrk, sizeof(info->csrk))) {
2168+
return BT_SMP_ERR_UNSPECIFIED;
2169+
}
21622170

21632171
if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) {
21642172
bt_keys_add_type(keys, BT_KEYS_LOCAL_CSRK);

0 commit comments

Comments
 (0)