Skip to content

Commit

Permalink
dispatcher: proper handling of socket parameter when is not last in a…
Browse files Browse the repository at this point in the history
…ttrs

- parsing socket function expects a null terminated string

(cherry picked from commit fd79adb)
  • Loading branch information
miconda committed Dec 17, 2015
1 parent 8807dbc commit c4adb48
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions modules/dispatcher/dispatch.c
Expand Up @@ -241,6 +241,7 @@ int add_dest2list(int id, str uri, int flags, int priority, str *attrs,
int orig_id = 0, orig_nr = 0;
str host;
int port, proto;
char c = 0;
ds_set_t *orig_ds_lists = ds_lists[list_idx];

/* check uri */
Expand Down Expand Up @@ -315,11 +316,23 @@ int add_dest2list(int id, str uri, int flags, int priority, str *attrs,

/* check socket attribute */
if (dp->attrs.socket.s && dp->attrs.socket.len > 0) {
/* parse_phostport(...) expects 0-terminated string
* - after socket parameter is either ';' or '\0' */
if(dp->attrs.socket.s[dp->attrs.socket.len]!='\0') {
c = dp->attrs.socket.s[dp->attrs.socket.len];
dp->attrs.socket.s[dp->attrs.socket.len] = '\0';
}
if (parse_phostport(dp->attrs.socket.s, &host.s, &host.len,
&port, &proto)!=0) {
LM_ERR("bad socket <%.*s>\n", dp->attrs.socket.len, dp->attrs.socket.s);
if(c!=0) {
dp->attrs.socket.s[dp->attrs.socket.len] = c;
}
goto err;
}
if(c!=0) {
dp->attrs.socket.s[dp->attrs.socket.len] = c;
}
dp->sock = grep_sock_info( &host, (unsigned short)port, proto);
if (dp->sock==0) {
LM_ERR("non-local socket <%.*s>\n", dp->attrs.socket.len, dp->attrs.socket.s);
Expand Down

0 comments on commit c4adb48

Please sign in to comment.