Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions bt-embedded/services/sdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,17 +846,14 @@ static void on_message_received(BteL2cap *l2cap, BteBufferReader *reader,

BteSdpServiceSearchReply reply;
reply.error_code = error_code;
if (UNLIKELY(error_code != 0)) {
if (UNLIKELY(error_code != 0 ||
!parse_service_search_reply(params, param_len,
&reply, &cont_state))) {
reply.total_count = reply.count = 0;
reply.has_more = false;
reply.handles = NULL;
req_complete = true;
} else {
bool ok = parse_service_search_reply(params, param_len,
&reply, &cont_state);
if (UNLIKELY(!ok)) {
goto end;
}
req_complete = !reply.has_more;
}
bool wants_more =
Expand All @@ -868,15 +865,12 @@ static void on_message_received(BteL2cap *l2cap, BteBufferReader *reader,

BteSdpServiceAttrReply reply;
reply.error_code = error_code;
if (UNLIKELY(error_code != 0)) {
if (UNLIKELY(error_code != 0 ||
!parse_service_attr_reply(sdp, params, param_len,
&reply, &cont_state))) {
reply.attr_list_de = NULL;
req_complete = true;
} else {
bool ok = parse_service_attr_reply(sdp, params, param_len,
&reply, &cont_state);
if (UNLIKELY(!ok)) {
goto end;
}
req_complete = cont_state[0] == 0;
}
if (req_complete) {
Expand All @@ -893,7 +887,7 @@ static void on_message_received(BteL2cap *l2cap, BteBufferReader *reader,
} else {
send_continuation_request(sdp, cont_state);
}
end:

if (params_buffer) bte_free(params_buffer);
bte_sdp_client_unref(sdp); /* temp reference */
}
Expand Down
76 changes: 76 additions & 0 deletions tests/test_sdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,40 @@ TEST_F(TestSdpClient, testServiceSearchFragmented) {
ASSERT_TRUE(m_backend.sentData().empty());
}

TEST_F(TestSdpClient, testServiceSearchUnparsable) {
std::vector<uint16_t> pattern = { 0x1122, 0x3344, 0x5566 };
std::vector<ServiceSearchReply> replies;
bool ok = m_sdp->serviceSearchReq(
pattern, 4, [&](const ServiceSearchReply &reply) {
replies.push_back(reply);
return false;
});
ASSERT_TRUE(ok);

uint8_t reqId = m_reqId++;

/* Verify that our request is as expected */
Buffer patternDe = {
0x35, 9,
0x19, 0x11, 0x22,
0x19, 0x33, 0x44,
0x19, 0x55, 0x66,
};
std::vector<Buffer> expectedData = {
makeServiceSearchReq(reqId, patternDe, 4),
};
ASSERT_EQ(m_backend.sentData(), expectedData);

/* Send a reply */
m_backend.sendData(makeSdpMsg(m_localCid, reqId, 0x03, Buffer{0xff}));
bte_handle_events();

std::vector<ServiceSearchReply> expectedReplies = {
ServiceSearchReply {},
};
ASSERT_EQ(replies, expectedReplies);
}

TEST_F(TestSdpClient, testServiceAttrSimple) {
Buffer idList {
0x35, 5,
Expand Down Expand Up @@ -366,3 +400,45 @@ TEST_F(TestSdpClient, testServiceSearchAttrSimple) {
};
ASSERT_EQ(replies, expectedReplies);
}

TEST_F(TestSdpClient, testServiceSearchAttrUnparsable) {
Buffer pattern {
0x35, 6,
0x19, 0x11, 0x22,
0x19, 0x33, 0x44,
};
Buffer idList {
0x35, 5,
0x0a, 0x00, 0x00, 0xff, 0xff,
};
std::vector<ServiceAttrReply> replies;
uint16_t maxCount = 0x1234;
bool ok =
m_sdp->serviceSearchAttrReq(pattern.data(), maxCount, idList.data(),
[&](const ServiceAttrReply &reply) {
replies.push_back(reply);
});
ASSERT_TRUE(ok);

uint8_t reqId = m_reqId++;

/* Verify that our request is as expected */
std::vector<Buffer> expectedData = {
makeServiceSearchAttrReq(reqId, pattern, maxCount, idList),
};
ASSERT_EQ(m_backend.sentData(), expectedData);

/* Send a reply */
Buffer attrList = {
0xff, 0xff, 0xff,
0xff, 0xff, 0xff,
0xff, 0xff, 0xff,
};
sendServiceSearchAttrRsp(reqId, attrList.size(), attrList);
bte_handle_events();

std::vector<ServiceAttrReply> expectedReplies = {
ServiceAttrReply {},
};
ASSERT_EQ(replies, expectedReplies);
}
Loading