Skip to content

Commit d14b435

Browse files
committed
[permissions] fix allow_uri() URI parameter
The parameter is a string, not pvar, so does not need to be evaluated Fixes #3645 Reported by @gostkov
1 parent 07de05e commit d14b435

1 file changed

Lines changed: 12 additions & 33 deletions

File tree

modules/permissions/permissions.c

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static int fix_part(void** param);
8282

8383
static int allow_routing(struct sip_msg* msg, int idx);
8484
static int allow_register(struct sip_msg* msg, int idx);
85-
static int allow_uri(struct sip_msg* msg, int idx, pv_spec_t *sp);
85+
static int allow_uri(struct sip_msg* msg, int idx, str *sp);
8686

8787
static int mod_init(void);
8888
static void mod_exit(void);
@@ -772,7 +772,7 @@ static int allow_register(struct sip_msg* msg, int idx)
772772
* -1: deny
773773
* 1: allow
774774
*/
775-
static int allow_uri(struct sip_msg* msg, int idx, pv_spec_t *sp)
775+
static int allow_uri(struct sip_msg* msg, int idx, str *uri_p)
776776
{
777777
struct hdr_field *from;
778778
int len;
@@ -786,23 +786,12 @@ static int allow_uri(struct sip_msg* msg, int idx, pv_spec_t *sp)
786786
return 1;
787787
}
788788

789-
/* looking for FROM HF */
790-
if ((!msg->from) && (parse_headers(msg, HDR_FROM_F, 0) == -1)) {
791-
LM_ERR("failed to parse message\n");
792-
return -1;
793-
}
794-
795-
if (!msg->from) {
796-
LM_ERR("FROM header field not found\n");
789+
/* we must call parse_from_header explicitly */
790+
if (parse_from_header(msg) < 0) {
791+
LM_ERR("failed to parse From body\n");
797792
return -1;
798793
}
799794

800-
/* we must call parse_from_header explicitly */
801-
if ((!(msg->from)->parsed) && (parse_from_header(msg) < 0)) {
802-
LM_ERR("failed to parse From body\n");
803-
return -1;
804-
}
805-
806795
from = msg->from;
807796
len = ((struct to_body*)from->parsed)->uri.len;
808797
if (len > EXPRESSION_LENGTH) {
@@ -812,26 +801,16 @@ static int allow_uri(struct sip_msg* msg, int idx, pv_spec_t *sp)
812801
strncpy(from_str, ((struct to_body*)from->parsed)->uri.s, len);
813802
from_str[len] = '\0';
814803

815-
if (sp && (pv_get_spec_value(msg, sp, &pv_val) == 0)) {
816-
if (pv_val.flags & PV_VAL_STR) {
817-
if (pv_val.rs.len > EXPRESSION_LENGTH) {
818-
LM_ERR("pseudo variable value is too "
819-
"long: %d chars\n", pv_val.rs.len);
820-
return -1;
821-
}
822-
strncpy(uri_str, pv_val.rs.s, pv_val.rs.len);
823-
uri_str[pv_val.rs.len] = '\0';
824-
} else {
825-
LM_ERR("pseudo variable value is not string\n");
804+
if (uri_p->len > EXPRESSION_LENGTH) {
805+
LM_ERR("URI value is too "
806+
"long: %d chars\n", uri_p->len);
826807
return -1;
827-
}
828-
} else {
829-
LM_ERR("cannot get pseudo variable value\n");
830-
return -1;
831808
}
809+
strncpy(uri_str, uri_p->s, uri_p->len);
810+
uri_str[uri_p->len] = '\0';
832811

833-
LM_DBG("looking for From: %s URI: %s\n", from_str, uri_str);
834-
/* rule exists in allow file */
812+
LM_DBG("looking for From: %s URI: %s\n", from_str, uri_str);
813+
/* rule exists in allow file */
835814
if (search_rule(allow[idx].rules, from_str, uri_str)) {
836815
LM_DBG("allow rule found => URI is allowed\n");
837816
return 1;

0 commit comments

Comments
 (0)