summaryrefslogtreecommitdiff
path: root/main/stun.c
diff options
context:
space:
mode:
authorScott Griepentrog <sgriepentrog@digium.com>2014-11-14 15:52:21 +0000
committerScott Griepentrog <sgriepentrog@digium.com>2014-11-14 15:52:21 +0000
commitba811ae1c3f80cb0d691fbe0dbdac2db1d4d960a (patch)
tree22feeedc09aab2cdfd39ad58efc26ad5f41255c3 /main/stun.c
parent2d9471ab1f18d12674ff29392f1fac2ee9129518 (diff)
stun: correct attribute string padding to match rfc
When sending the USERNAME attribute in an RTP STUN response, the implementation in append_attr_string passed the actual length, instead of padding it up to a multiple of four bytes as required by the RFC 3489. This change adds separate variables for the string and padded attributed lengths, and performs padding correctly. Reported by: Thomas Arimont Review: https://reviewboard.asterisk.org/r/4139/ ........ Merged revisions 427874 from http://svn.asterisk.org/svn/asterisk/branches/11 ........ Merged revisions 427875 from http://svn.asterisk.org/svn/asterisk/branches/12 ........ Merged revisions 427876 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@427877 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/stun.c')
-rw-r--r--main/stun.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/main/stun.c b/main/stun.c
index 268bbe4de..e0a25594f 100644
--- a/main/stun.c
+++ b/main/stun.c
@@ -201,12 +201,15 @@ static int stun_process_attr(struct stun_state *state, struct stun_attr *attr)
/*! \brief append a string to an STUN message */
static void append_attr_string(struct stun_attr **attr, int attrval, const char *s, int *len, int *left)
{
- int size = sizeof(**attr) + strlen(s);
+ int str_length = strlen(s);
+ int attr_length = str_length + ((~(str_length - 1)) & 0x3);
+ int size = sizeof(**attr) + attr_length;
if (*left > size) {
(*attr)->attr = htons(attrval);
- (*attr)->len = htons(strlen(s));
- memcpy((*attr)->value, s, strlen(s));
- (*attr) = (struct stun_attr *)((*attr)->value + strlen(s));
+ (*attr)->len = htons(attr_length);
+ memcpy((*attr)->value, s, str_length);
+ memset((*attr)->value + str_length, 0, attr_length - str_length);
+ (*attr) = (struct stun_attr *)((*attr)->value + attr_length);
*len += size;
*left -= size;
}