diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2008-06-22 21:59:42 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2008-06-22 21:59:42 +0000 |
commit | 0e1789b3f1897512eb30d63c8e9803f1461446c1 (patch) | |
tree | 3ad1c147a43aaba27eb12fa1af66ed149041ddb5 /src | |
parent | a3648e0df0ff53fef74e5437ff089aef96209db2 (diff) |
Add safe version of sdp_extract_pdu function
Diffstat (limited to 'src')
-rw-r--r-- | src/sdp.c | 30 |
1 files changed, 24 insertions, 6 deletions
@@ -1323,7 +1323,7 @@ void sdp_print_service_attr(sdp_list_t *svcAttrList) } #endif -sdp_record_t *sdp_extract_pdu(const uint8_t *buf, int *scanned) +sdp_record_t *sdp_extract_pdu_safe(const uint8_t *buf, int bufsize, int *scanned) { int extracted = 0, seqlen = 0; uint8_t dtd; @@ -1331,21 +1331,30 @@ sdp_record_t *sdp_extract_pdu(const uint8_t *buf, int *scanned) sdp_record_t *rec = sdp_record_alloc(); const uint8_t *p = buf; - *scanned = sdp_extract_seqtype(buf, &dtd, &seqlen); + *scanned = sdp_extract_seqtype_safe(buf, bufsize, &dtd, &seqlen); p += *scanned; + bufsize -= *scanned; rec->attrlist = NULL; - while (extracted < seqlen) { + + while (extracted < seqlen && bufsize > 0) { int n = sizeof(uint8_t), attrlen = 0; sdp_data_t *data = NULL; - SDPDBG("Extract PDU, sequenceLength: %d localExtractedLength: %d", seqlen, extracted); + SDPDBG("Extract PDU, sequenceLength: %d localExtractedLength: %d", + seqlen, extracted); + + if (bufsize < n + sizeof(uint16_t)) { + SDPERR("Unexpected end of packet"); + break; + } + dtd = *(uint8_t *) p; attr = ntohs(bt_get_unaligned((uint16_t *) (p + n))); n += sizeof(uint16_t); SDPDBG("DTD of attrId : %d Attr id : 0x%x \n", dtd, attr); - data = sdp_extract_attr(p + n, &attrlen, rec); + data = sdp_extract_attr_safe(p + n, bufsize - n, &attrlen, rec); SDPDBG("Attr id : 0x%x attrValueLength : %d\n", attr, attrlen); @@ -1363,9 +1372,11 @@ sdp_record_t *sdp_extract_pdu(const uint8_t *buf, int *scanned) extracted += n; p += n; + bufsize -= n; sdp_attr_replace(rec, attr, data); + SDPDBG("Extract PDU, seqLength: %d localExtractedLength: %d", - seqlen, extracted); + seqlen, extracted); } #ifdef SDP_DEBUG SDPDBG("Successful extracting of Svc Rec attributes\n"); @@ -1375,6 +1386,13 @@ sdp_record_t *sdp_extract_pdu(const uint8_t *buf, int *scanned) return rec; } +sdp_record_t *sdp_extract_pdu(const uint8_t *buf, int *scanned) +{ + /* Assume buf points to a buffer of size at least SDP_MAX_ATTR_LEN, + because we don't have any better information */ + return sdp_extract_pdu_safe(buf, SDP_MAX_ATTR_LEN, scanned); +} + #ifdef SDP_DEBUG static void print_dataseq(sdp_data_t *p) { |