Skip to content

Commit b250754

Browse files
Thalleyfabiobaltieri
authored andcommitted
Bluetooth: TBS: Fix type of uri in bt_tbs_valid_uri
The function had marked the type as char *, but it was in fact not a string but rather a uint8_t array. Marked the type properly and added a cast when using it with strings. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
1 parent 9c23eff commit b250754

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

subsys/bluetooth/audio/tbs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,7 @@ int bt_tbs_originate(uint8_t bearer_index, char *remote_uri,
17411741

17421742
if (tbs == NULL || inst_is_gtbs(tbs)) {
17431743
return -EINVAL;
1744-
} else if (!bt_tbs_valid_uri(remote_uri, strlen(remote_uri))) {
1744+
} else if (!bt_tbs_valid_uri((uint8_t *)remote_uri, strlen(remote_uri))) {
17451745
LOG_DBG("Invalid URI %s", remote_uri);
17461746
return -EINVAL;
17471747
}
@@ -1937,10 +1937,10 @@ int bt_tbs_remote_incoming(uint8_t bearer_index, const char *to,
19371937

19381938
if (inst == NULL || inst_is_gtbs(inst)) {
19391939
return -EINVAL;
1940-
} else if (!bt_tbs_valid_uri(to, strlen(to))) {
1940+
} else if (!bt_tbs_valid_uri((uint8_t *)to, strlen(to))) {
19411941
LOG_DBG("Invalid \"to\" URI: %s", to);
19421942
return -EINVAL;
1943-
} else if (!bt_tbs_valid_uri(from, strlen(from))) {
1943+
} else if (!bt_tbs_valid_uri((uint8_t *)from, strlen(from))) {
19441944
LOG_DBG("Invalid \"from\" URI: %s", from);
19451945
return -EINVAL;
19461946
}

subsys/bluetooth/audio/tbs_internal.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,29 +177,28 @@ static inline const char *bt_tbs_term_reason_str(uint8_t reason)
177177
}
178178

179179
/**
180-
* @brief Checks if a string contains a colon (':') followed by a printable
180+
* @brief Checks if @p uri contains a colon (':') followed by a printable
181181
* character. Minimal uri is "a:b".
182182
*
183183
* @param uri The uri "scheme:id"
184184
* @param len The length of uri
185185
* @return true If the above is true
186186
* @return false If the above is not true
187187
*/
188-
static inline bool bt_tbs_valid_uri(const char *uri, size_t len)
188+
static inline bool bt_tbs_valid_uri(const uint8_t *uri, size_t uri_len)
189189
{
190190
if (!uri) {
191191
return false;
192192
}
193193

194-
if (len > CONFIG_BT_TBS_MAX_URI_LENGTH ||
195-
len < BT_TBS_MIN_URI_LEN) {
194+
if (uri_len > CONFIG_BT_TBS_MAX_URI_LENGTH || uri_len < BT_TBS_MIN_URI_LEN) {
196195
return false;
197196
} else if (uri[0] < FIRST_PRINTABLE_ASCII_CHAR) {
198197
/* Invalid first char */
199198
return false;
200199
}
201200

202-
for (int i = 1; i < len; i++) {
201+
for (size_t i = 1; i < uri_len; i++) {
203202
if (uri[i] == ':' && uri[i + 1] >= FIRST_PRINTABLE_ASCII_CHAR) {
204203
return true;
205204
}

0 commit comments

Comments
 (0)