Skip to content

Commit 17223f1

Browse files
MariuszSkamracarlescufi
authored andcommitted
Bluetooth: audio: Fix metadata length checks
This fixes metadata length checks for BT_AUDIO_METADATA_TYPE_EXTENDED and BT_AUDIO_METADATA_TYPE_VENDOR that should be at least 2 bytes long. Signed-off-by: Mariusz Skamra <[email protected]>
1 parent db5767e commit 17223f1

File tree

7 files changed

+28
-21
lines changed

7 files changed

+28
-21
lines changed

samples/bluetooth/hap_ha/src/bap_unicast_sr.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,10 @@ static bool valid_metadata_type(uint8_t type, uint8_t len)
290290
}
291291

292292
return true;
293-
case BT_AUDIO_METADATA_TYPE_EXTENDED: /* 1 - 255 octets */
294-
case BT_AUDIO_METADATA_TYPE_VENDOR: /* 1 - 255 octets */
295-
if (len < 1) {
293+
case BT_AUDIO_METADATA_TYPE_EXTENDED: /* 2 - 255 octets */
294+
case BT_AUDIO_METADATA_TYPE_VENDOR: /* 2 - 255 octets */
295+
/* At least Extended Metadata Type / Company_ID should be there */
296+
if (len < 2) {
296297
return false;
297298
}
298299

samples/bluetooth/tmap_peripheral/src/bap_unicast_sr.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,10 @@ static bool valid_metadata_type(uint8_t type, uint8_t len)
239239
}
240240

241241
return true;
242-
case BT_AUDIO_METADATA_TYPE_EXTENDED: /* 1 - 255 octets */
243-
case BT_AUDIO_METADATA_TYPE_VENDOR: /* 1 - 255 octets */
244-
if (len < 1) {
242+
case BT_AUDIO_METADATA_TYPE_EXTENDED: /* 2 - 255 octets */
243+
case BT_AUDIO_METADATA_TYPE_VENDOR: /* 2 - 255 octets */
244+
/* At least Extended Metadata Type / Company_ID should be there */
245+
if (len < 2) {
245246
return false;
246247
}
247248

samples/bluetooth/unicast_audio_server/src/main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,10 @@ static bool valid_metadata_type(uint8_t type, uint8_t len)
431431
}
432432

433433
return true;
434-
case BT_AUDIO_METADATA_TYPE_EXTENDED: /* 1 - 255 octets */
435-
case BT_AUDIO_METADATA_TYPE_VENDOR: /* 1 - 255 octets */
436-
if (len < 1) {
434+
case BT_AUDIO_METADATA_TYPE_EXTENDED: /* 2 - 255 octets */
435+
case BT_AUDIO_METADATA_TYPE_VENDOR: /* 2 - 255 octets */
436+
/* At least Extended Metadata Type / Company_ID should be there */
437+
if (len < 2) {
437438
return false;
438439
}
439440

subsys/bluetooth/audio/shell/bap.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,10 @@ static bool valid_metadata_type(uint8_t type, uint8_t len)
511511
}
512512

513513
return true;
514-
case BT_AUDIO_METADATA_TYPE_EXTENDED: /* 1 - 255 octets */
515-
case BT_AUDIO_METADATA_TYPE_VENDOR: /* 1 - 255 octets */
516-
if (len < 1) {
514+
case BT_AUDIO_METADATA_TYPE_EXTENDED: /* 2 - 255 octets */
515+
case BT_AUDIO_METADATA_TYPE_VENDOR: /* 2 - 255 octets */
516+
/* At least Extended Metadata Type / Company_ID should be there */
517+
if (len < 2) {
517518
return false;
518519
}
519520

tests/bluetooth/tester/src/btp_bap.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,10 @@ static bool valid_metadata_type(uint8_t type, uint8_t len, const uint8_t *data)
353353
}
354354

355355
return true;
356-
case BT_AUDIO_METADATA_TYPE_EXTENDED: /* 1 - 255 octets */
357-
case BT_AUDIO_METADATA_TYPE_VENDOR: /* 1 - 255 octets */
358-
if (len < 1) {
356+
case BT_AUDIO_METADATA_TYPE_EXTENDED: /* 2 - 255 octets */
357+
case BT_AUDIO_METADATA_TYPE_VENDOR: /* 2 - 255 octets */
358+
/* At least Extended Metadata Type / Company_ID should be there */
359+
if (len < 2) {
359360
return false;
360361
}
361362

tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,10 @@ static bool valid_metadata_type(uint8_t type, uint8_t len)
182182
}
183183

184184
return true;
185-
case BT_AUDIO_METADATA_TYPE_EXTENDED: /* 1 - 255 octets */
186-
case BT_AUDIO_METADATA_TYPE_VENDOR: /* 1 - 255 octets */
187-
if (len < 1) {
185+
case BT_AUDIO_METADATA_TYPE_EXTENDED: /* 2 - 255 octets */
186+
case BT_AUDIO_METADATA_TYPE_VENDOR: /* 2 - 255 octets */
187+
/* At least Extended Metadata Type / Company_ID should be there */
188+
if (len < 2) {
188189
return false;
189190
}
190191

tests/bsim/bluetooth/audio/src/cap_acceptor_test.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,10 @@ static bool valid_metadata_type(uint8_t type, uint8_t len)
347347
}
348348

349349
return true;
350-
case BT_AUDIO_METADATA_TYPE_EXTENDED: /* 1 - 255 octets */
351-
case BT_AUDIO_METADATA_TYPE_VENDOR: /* 1 - 255 octets */
352-
if (len < 1) {
350+
case BT_AUDIO_METADATA_TYPE_EXTENDED: /* 2 - 255 octets */
351+
case BT_AUDIO_METADATA_TYPE_VENDOR: /* 2 - 255 octets */
352+
/* At least Extended Metadata Type / Company_ID should be there */
353+
if (len < 2) {
353354
return false;
354355
}
355356

0 commit comments

Comments
 (0)