From: Bart Westgeest <bart@elbrys.com>
To: linux-bluetooth@vger.kernel.org
Cc: Bart Westgeest <bart@elbrys.com>
Subject: [PATCH 2/3] sdp: Limit side effects of sdp_get_data_type and sdp_get_data_size
Date: Mon, 19 Nov 2012 14:04:31 -0500 [thread overview]
Message-ID: <1353351872-10628-3-git-send-email-bart@elbrys.com> (raw)
In-Reply-To: <1353351872-10628-1-git-send-email-bart@elbrys.com>
Remove modification of buf->buf_size in 'get' functions. Data is
still indirectly modified due to recursive nature of code.
Renamed sdp_get_data_type to sdp_get_data_type_size.
---
lib/sdp.c | 26 +++++++++-----------------
1 file changed, 9 insertions(+), 17 deletions(-)
diff --git a/lib/sdp.c b/lib/sdp.c
index dba3f59..026163e 100644
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -633,37 +633,32 @@ void sdp_set_seq_len(uint8_t *ptr, uint32_t length)
}
}
-static int sdp_get_data_type(sdp_buf_t *buf, uint8_t dtd)
+static int sdp_get_data_type_size(uint8_t dtd)
{
- int data_type = 0;
-
- data_type += sizeof(uint8_t);
+ int size = sizeof(uint8_t);
switch (dtd) {
case SDP_SEQ8:
case SDP_TEXT_STR8:
case SDP_URL_STR8:
case SDP_ALT8:
- data_type += sizeof(uint8_t);
+ size += sizeof(uint8_t);
break;
case SDP_SEQ16:
case SDP_TEXT_STR16:
case SDP_URL_STR16:
case SDP_ALT16:
- data_type += sizeof(uint16_t);
+ size += sizeof(uint16_t);
break;
case SDP_SEQ32:
case SDP_TEXT_STR32:
case SDP_URL_STR32:
case SDP_ALT32:
- data_type += sizeof(uint32_t);
+ size += sizeof(uint32_t);
break;
}
- if (!buf->data)
- buf->buf_size += data_type;
-
- return data_type;
+ return size;
}
void sdp_set_attrid(sdp_buf_t *buf, uint16_t attr)
@@ -762,9 +757,6 @@ static int sdp_get_data_size(sdp_buf_t *buf, sdp_data_t *d)
break;
}
- if (!buf->data)
- buf->buf_size += data_size;
-
return data_size;
}
@@ -783,8 +775,8 @@ static int sdp_gen_buffer(sdp_buf_t *buf, sdp_data_t *d)
/* attribute length */
buf->buf_size += sizeof(uint8_t) + sizeof(uint16_t);
- sdp_get_data_type(buf, d->dtd);
- sdp_get_data_size(buf, d);
+ buf->buf_size += sdp_get_data_type_size(d->dtd);
+ buf->buf_size += sdp_get_data_size(buf, d);
if (buf->buf_size > UCHAR_MAX && d->dtd == SDP_SEQ8)
buf->buf_size += sizeof(uint8_t);
@@ -803,7 +795,7 @@ int sdp_gen_pdu(sdp_buf_t *buf, sdp_data_t *d)
uint128_t u128;
uint8_t *seqp = buf->data + buf->data_size;
- pdu_size = sdp_get_data_type(buf, dtd);
+ pdu_size = sdp_get_data_type_size(dtd);
buf->data_size += pdu_size;
data_size = sdp_get_data_size(buf, d);
--
1.7.10.4
next prev parent reply other threads:[~2012-11-19 19:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-19 19:04 [PATCH 0/3] Fix corrupted SDP response for sequence size > 256 Bart Westgeest
2012-11-19 19:04 ` [PATCH 1/3] sdp: Inlined single use of function sdp_set_data_type Bart Westgeest
2012-11-19 19:04 ` Bart Westgeest [this message]
2012-11-19 20:24 ` [PATCH 2/3] sdp: Limit side effects of sdp_get_data_type and sdp_get_data_size Anderson Lizardo
2012-11-19 21:06 ` Bart Westgeest
2012-11-19 19:04 ` [PATCH 3/3] sdp: Upgrade datatype SEQ8 to SEQ16 when data size is greater than 256 Bart Westgeest
2012-11-19 20:38 ` Anderson Lizardo
2012-11-19 21:33 ` Bart Westgeest
2012-11-20 12:57 ` [PATCH 0/3] Fix corrupted SDP response for sequence size > 256 Johan Hedberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1353351872-10628-3-git-send-email-bart@elbrys.com \
--to=bart@elbrys.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).