Skip to content

Commit 38d0e6e

Browse files
committed
sdp: reject malformed bandwidth lines
1 parent f86942e commit 38d0e6e

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

parser/sdp/sdp_helpr_funcs.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,30 +328,37 @@ int extract_bwidth(str *body, str *bwtype, str *bwwitdth)
328328
{
329329
char *cp, *cp1;
330330
int len;
331+
str bline;
331332

332333
cp1 = NULL;
333334
for (cp = body->s; (len = body->s + body->len - cp) > 0;) {
334335
cp1 = (char*)l_memmem(cp, "b=", len, 2);
335-
if (cp1 == NULL || cp1[-1] == '\n' || cp1[-1] == '\r')
336+
if (cp1 == NULL || cp1 == body->s ||
337+
cp1[-1] == '\n' || cp1[-1] == '\r')
336338
break;
337339
cp = cp1 + 2;
338340
}
339341
if (cp1 == NULL)
340342
return -1;
341343

342-
bwtype->s = cp1 + 2;
343-
bwtype->len = eat_line(bwtype->s, body->s + body->len - bwtype->s) - bwtype->s;
344-
trim_len(bwtype->len, bwtype->s, *bwtype);
344+
bline.s = cp1 + 2;
345+
bline.len = eat_line(bline.s, body->s + body->len - bline.s) - bline.s;
346+
trim_len(bline.len, bline.s, bline);
345347

346-
cp = bwtype->s;
347-
len = bwtype->len;
348+
cp = bline.s;
349+
len = bline.len;
348350
cp1 = (char*)l_memmem(cp, ":", len, 1);
351+
if (cp1 == NULL) {
352+
LM_ERR("invalid encoding in `b=%.*s'\n", bline.len, bline.s);
353+
return -1;
354+
}
349355
len -= cp1 - cp;
350356
if (len <= 0) {
351-
LM_ERR("invalid encoding in `b=%.*s'\n", bwtype->len, bwtype->s);
357+
LM_ERR("invalid encoding in `b=%.*s'\n", bline.len, bline.s);
352358
return -1;
353359
}
354360
bwtype->len = cp1 - cp;
361+
bwtype->s = cp;
355362

356363
/* skip ':' */
357364
bwwitdth->s = cp1 + 1;
@@ -653,4 +660,3 @@ char* get_sdp_hdr_field(char* buf, char* end, struct hdr_field* hdr)
653660
hdr->len=tmp-hdr->name.s;
654661
return tmp;
655662
}
656-

0 commit comments

Comments
 (0)