Skip to content

Commit

Permalink
drouting: enforce gwid format check
Browse files Browse the repository at this point in the history
Make sure the gwid of a gateway complies with a specific format,
otherwise it will not be able to be used in a gwlist, either in carrier
or in a rule.
  • Loading branch information
razvancrainea committed Dec 11, 2018
1 parent 489589c commit eeb6b5b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion modules/drouting/routing.c
Expand Up @@ -43,6 +43,9 @@
#include "prefix_tree.h"
#include "parse.h"

#define is_valid_gw_char(_c) \
(isalpha(_c) || isdigit(_c) || (_c)=='_' || (_c)=='-' || (_c)=='.')


extern int dr_force_dns;

Expand Down Expand Up @@ -129,7 +132,7 @@ int parse_destination_list(rt_data_t* rd, char *dstlist,

/* eat the destination ID (alphanumerical) */
id.s = tmp;
while( *tmp && (isalpha(*tmp) || isdigit(*tmp) || (*tmp)=='_' || (*tmp)=='-') )
while( *tmp && is_valid_gw_char(*tmp))
tmp++;
if (id.s == tmp) {
LM_ERR("bad id '%c' (%d)[%s]\n",
Expand Down Expand Up @@ -458,6 +461,7 @@ add_dst(
int l_ip,l_pri,l_attrs,l_id;
#define GWABUF_MAX_SIZE 512
char gwabuf[GWABUF_MAX_SIZE];
char *p;
union sockaddr_union sau;
struct proxy_l *proxy;
unsigned int sip_prefix;
Expand All @@ -474,6 +478,13 @@ add_dst(
l_pri = pri?strlen(pri):0;
l_attrs = attrs?strlen(attrs):0;

/* check the ID of the gateway */
for (p = id + l_id - 1; p >= id; p--)
if (!is_valid_gw_char(*p)) {
LM_ERR("invalid char in gateway's name [%c]\n", *p);
goto err_exit;
}

/* check if GW address starts with 'sip' or 'sips' */
if (l_ip>5) {
if ( strncasecmp("sip:", ip, 4)==0)
Expand Down

0 comments on commit eeb6b5b

Please sign in to comment.