Skip to content

Commit 3ce1046

Browse files
authored
Merge pull request #214 from BIIIANG/master
stun: add checks for attribute length before read from it
2 parents 3f17604 + c3bbc50 commit 3ce1046

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

libsofia-sip-ua/stun/stun_common.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ int stun_parse_attr_error_code(stun_attr_t *attr, const unsigned char *p, unsign
250250
uint32_t tmp;
251251
stun_attr_errorcode_t *error;
252252

253+
if (len < 4) {
254+
return -1;
255+
}
256+
253257
memcpy(&tmp, p, sizeof(uint32_t));
254258
tmp = ntohl(tmp);
255259
error = (stun_attr_errorcode_t *) malloc(sizeof(*error));
@@ -271,6 +275,11 @@ int stun_parse_attr_uint32(stun_attr_t *attr, const unsigned char *p, unsigned l
271275
{
272276
uint32_t tmp;
273277
stun_attr_changerequest_t *cr;
278+
279+
if (len < 4) {
280+
return -1;
281+
}
282+
274283
cr = (stun_attr_changerequest_t *) malloc(sizeof(*cr));
275284
memcpy(&tmp, p, sizeof(uint32_t));
276285
cr->value = ntohl(tmp);

0 commit comments

Comments
 (0)