@@ -83,6 +83,18 @@ NET_BUF_POOL_FIXED_DEFINE(sdp_pool, CONFIG_BT_MAX_CONN, BT_L2CAP_BUF_SIZE(SDP_MT
83
83
84
84
#define SDP_CLIENT_MTU 64
85
85
86
+ #define SDP_SA_MAX_ATTR_BYTE_COUNT 0xffff
87
+ #define SDP_SA_MIN_ATTR_BYTE_COUNT 0x0007
88
+
89
+ #define SDP_SA_ATTR_BYTE_IN_RANGE (count ) \
90
+ ((count) >= SDP_SA_MIN_ATTR_BYTE_COUNT && (count) <= SDP_SA_MAX_ATTR_BYTE_COUNT)
91
+
92
+ #define SDP_SSA_MAX_ATTR_BYTE_COUNT 0xffff
93
+ #define SDP_SSA_MIN_ATTR_BYTE_COUNT 0x0007
94
+
95
+ #define SDP_SSA_ATTR_BYTE_IN_RANGE (count ) \
96
+ ((count) >= SDP_SSA_MIN_ATTR_BYTE_COUNT && (count) <= SDP_SSA_MAX_ATTR_BYTE_COUNT)
97
+
86
98
enum sdp_client_state {
87
99
SDP_CLIENT_RELEASED ,
88
100
SDP_CLIENT_CONNECTING ,
@@ -1273,6 +1285,10 @@ static uint16_t sdp_svc_att_req(struct bt_sdp *sdp, struct net_buf *buf, uint16_
1273
1285
1274
1286
svc_rec_hdl = net_buf_pull_be32 (buf );
1275
1287
max_att_len = net_buf_pull_be16 (buf );
1288
+ if (!SDP_SA_ATTR_BYTE_IN_RANGE (max_att_len )) {
1289
+ LOG_WRN ("Invalid max attribute length %u" , max_att_len );
1290
+ return BT_SDP_INVALID_SYNTAX ;
1291
+ }
1276
1292
1277
1293
/* Set up the filters */
1278
1294
res = get_att_search_list (buf , filter , ARRAY_SIZE (filter ), & num_filters );
@@ -1404,6 +1420,11 @@ static uint16_t sdp_svc_search_att_req(struct bt_sdp *sdp, struct net_buf *buf,
1404
1420
}
1405
1421
1406
1422
max_att_len = net_buf_pull_be16 (buf );
1423
+ if (!SDP_SSA_ATTR_BYTE_IN_RANGE (max_att_len )) {
1424
+ LOG_WRN ("Invalid max attribute length %u" , max_att_len );
1425
+ return BT_SDP_INVALID_SYNTAX ;
1426
+ }
1427
+
1407
1428
if (max_att_len < sizeof (* seq )) {
1408
1429
LOG_WRN ("Invalid maximum attribute byte count %u < %u" , max_att_len , sizeof (* seq ));
1409
1430
return BT_SDP_INVALID_SYNTAX ;
@@ -1860,13 +1881,19 @@ static int sdp_client_sa_search(struct bt_sdp_client *session,
1860
1881
/* Update context param directly. */
1861
1882
session -> param = param ;
1862
1883
1884
+ len = net_buf_tailroom (session -> rec_buf );
1885
+ if (!SDP_SA_ATTR_BYTE_IN_RANGE (len )) {
1886
+ LOG_WRN ("No more space to start next SDP discovery" );
1887
+ return - ENOMEM ;
1888
+ }
1889
+
1863
1890
buf = bt_sdp_create_pdu ();
1864
1891
1865
1892
/* Add service record handle */
1866
1893
net_buf_add_be32 (buf , param -> handle );
1867
1894
1868
1895
/* Set attribute max bytes count to be returned from server */
1869
- net_buf_add_be16 (buf , net_buf_tailroom ( session -> rec_buf ) );
1896
+ net_buf_add_be16 (buf , len );
1870
1897
1871
1898
/* Check the tailroom of the buffer */
1872
1899
len = sdp_client_get_total_len (session , param );
@@ -1908,6 +1935,12 @@ static int sdp_client_ssa_search(struct bt_sdp_client *session,
1908
1935
/* Update context param directly. */
1909
1936
session -> param = param ;
1910
1937
1938
+ len = net_buf_tailroom (session -> rec_buf );
1939
+ if (!SDP_SSA_ATTR_BYTE_IN_RANGE (len )) {
1940
+ LOG_WRN ("No more space to start next SDP discovery" );
1941
+ return - ENOMEM ;
1942
+ }
1943
+
1911
1944
buf = bt_sdp_create_pdu ();
1912
1945
1913
1946
/* BT_SDP_SEQ8 means length of sequence is on additional next byte */
@@ -1940,7 +1973,7 @@ static int sdp_client_ssa_search(struct bt_sdp_client *session,
1940
1973
}
1941
1974
1942
1975
/* Set attribute max bytes count to be returned from server */
1943
- net_buf_add_be16 (buf , net_buf_tailroom ( session -> rec_buf ) );
1976
+ net_buf_add_be16 (buf , len );
1944
1977
1945
1978
/* Check the tailroom of the buffer */
1946
1979
len = sdp_client_get_total_len (session , param );
0 commit comments