[PATCH BlueZ] sdpd-request: Fix unchecked malloc
zuohsh <[email protected]>
| Newsgroups | org.kernel.vger.linux-bluetooth |
|---|---|
| Message-ID | <[email protected]> |
Fix unchecked malloc in request processing in service_search_attr_req()
and process_request().Also add SDP_INSUFFICIENT_RESOURCES (0x0006) which
is defined by the Bluetooth Core Specification but was missing from sdp.h.
---
lib/bluetooth/sdp.h | 1 +
src/sdpd-request.c | 10 ++++++++++
2 files changed, 11 insertions(+)
diff --git a/lib/bluetooth/sdp.h b/lib/bluetooth/sdp.h
index 6f05d4321..30a99ec14 100644
--- a/lib/bluetooth/sdp.h
+++ b/lib/bluetooth/sdp.h
@@ -413,6 +413,7 @@ extern "C" {
#define SDP_INVALID_SYNTAX 0x0003
#define SDP_INVALID_PDU_SIZE 0x0004
#define SDP_INVALID_CSTATE 0x0005
+#define SDP_INSUFFICIENT_RESOURCES 0x0006
/*
* SDP PDU
diff --git a/src/sdpd-request.c b/src/sdpd-request.c
index c78bfdffa..7d169482b 100644
--- a/src/sdpd-request.c
+++ b/src/sdpd-request.c
@@ -909,6 +909,10 @@ static int service_search_attr_req(sdp_req_t *req, sdp_buf_t *buf)
svcList = sdp_get_record_list();
tmpbuf.data = malloc(USHRT_MAX);
+ if (!tmpbuf.data) {
+ status = SDP_INSUFFICIENT_RESOURCES;
+ goto done;
+ }
tmpbuf.data_size = 0;
tmpbuf.buf_size = USHRT_MAX;
memset(tmpbuf.data, 0, USHRT_MAX);
@@ -1013,6 +1017,12 @@ static void process_request(sdp_req_t *req)
uint8_t *buf = malloc(USHRT_MAX);
int status = SDP_INVALID_SYNTAX;
+ if (!buf) {
+ free(req->buf);
+ req->buf = NULL;
+ return;
+ }
+
memset(buf, 0, USHRT_MAX);
rsp.data = buf + sizeof(sdp_pdu_hdr_t);
rsp.data_size = 0;
--
2.43.0