Skip to content

Commit

Permalink
sdp: make parse_sdp_sessions() accept optional \r\n at begin
Browse files Browse the repository at this point in the history
Instead of having to provide a mandatory \r\n at the begin of the SDP
body that is going to be parsed, this is now optional. Thus the SDP can
now start directly with the `v=` line.

This commit also fixes two other issues:
1. the function might underflow if `v=` is found in the first two chars
2. if the SDP has some garbage at the begining, then it is valid, the
   previous function would have validated it
  • Loading branch information
razvancrainea committed Feb 18, 2020
1 parent b7b22d6 commit ab4cc76
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
6 changes: 3 additions & 3 deletions modules/sngtc/sngtc.c
Expand Up @@ -437,14 +437,14 @@ int store_sngtc_info(struct dlg_cell *dlg, str *body)
memset(info, 0, sizeof(*info));

lock_init(&info->lock);
info->caller_sdp.s = shm_malloc(body->len + 2);
info->caller_sdp.s = shm_malloc(body->len);
if (!info->caller_sdp.s) {
LM_ERR("no more shm\n");
goto exit;
}

info->caller_sdp.len = body->len + 2; /* SDP parser needs starting CRLF */
memcpy(info->caller_sdp.s, body->s - 2, info->caller_sdp.len);
info->caller_sdp.len = body->len; /* SDP parser needs starting CRLF */
memcpy(info->caller_sdp.s, body->s, info->caller_sdp.len);

st.s = (void *)&info;
st.len = sizeof(void *);
Expand Down
19 changes: 16 additions & 3 deletions parser/sdp/sdp.c
Expand Up @@ -392,9 +392,22 @@ int parse_sdp_session(str *sdp_body, int session_num, str *cnt_disp, sdp_info_t*
* unconditionally.
*/
bodylimit = body.s + body.len;
v1p = find_sdp_line(body.s, bodylimit, 'v');
if (v1p == NULL) {
LM_ERR("no sessions in SDP\n");
if (body.len < 2) {
LM_ERR("body too short!\n");
return -1;
}
v1p = body.s;
/* skip over the first initial \r\n (optional) */
if (*v1p == '\r' || *v1p == '\n')
v1p++;
if (*v1p == '\r' || *v1p == '\n')
v1p++;
if (v1p + 1 >= bodylimit) {
LM_ERR("body too short %ld!\n", bodylimit - v1p);
return -1;
}
if (*v1p != 'v' || *(v1p+1) != '=') {
LM_ERR("invalid SDP start: [%c%c]\n", *v1p, *(v1p + 1));
return -1;
}
/* get session origin */
Expand Down

0 comments on commit ab4cc76

Please sign in to comment.