UPSTREAM: sdp: Fix Out-of-bounds heap read in service_search_attr_req function

Check if there is enough data to continue otherwise return an error.

BUG=chromium:764477
TEST=Run bluetooth tests

(cherry picked from commit 9e009647b14e810e06626dde7f1bb9ea3c375d09)
Signed-off-by: Guenter Roeck <groeck@chromium.org>

Change-Id: Ib9b49cb17d5964daad5c9b377744020f968c0521
Reviewed-on: https://chromium-review.googlesource.com/664819
Trybot-Ready: Guenter Roeck <groeck@chromium.org>
Reviewed-by: Mattias Nissler <mnissler@chromium.org>
Commit-Queue: Guenter Roeck <groeck@chromium.org>
Tested-by: Guenter Roeck <groeck@chromium.org>
diff --git a/src/sdpd-request.c b/src/sdpd-request.c
index 1eefdce..318d044 100644
--- a/src/sdpd-request.c
+++ b/src/sdpd-request.c
@@ -917,7 +917,7 @@
 	} else {
 		/* continuation State exists -> get from cache */
 		sdp_buf_t *pCache = sdp_get_cached_rsp(cstate);
-		if (pCache) {
+		if (pCache && cstate->cStateValue.maxBytesSent < pCache->data_size) {
 			uint16_t sent = MIN(max, pCache->data_size - cstate->cStateValue.maxBytesSent);
 			pResponse = pCache->data;
 			memcpy(buf->data, pResponse + cstate->cStateValue.maxBytesSent, sent);