From fe43991e3dc6c46e2781d21369f5e268de7baef9 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Tue, 10 Oct 2017 18:11:31 +0200 Subject: Implement match on arguments position --- src/sp_config_keywords.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/sp_config_keywords.c') diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index 29f1bfc..1f48852 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c @@ -144,7 +144,9 @@ int parse_cookie_encryption(char *line) { int parse_disabled_functions(char *line) { int ret = 0; bool enable = true, disable = false; + char *pos = NULL; sp_disabled_function *df = pecalloc(sizeof(*df), 1, 1); + df->pos = -1; sp_config_functions sp_config_funcs_disabled_functions[] = { {parse_empty, SP_TOKEN_ENABLE, &(enable)}, @@ -169,6 +171,7 @@ int parse_disabled_functions(char *line) { {parse_regexp, SP_TOKEN_RET_REGEXP, &(df->r_ret)}, {parse_php_type, SP_TOKEN_RET_TYPE, &(df->ret_type)}, {parse_str, SP_TOKEN_LOCAL_VAR, &(df->var)}, + {parse_str, SP_TOKEN_VALUE_ARG_POS, &(pos)}, {0}}; ret = parse_keywords(sp_config_funcs_disabled_functions, line); @@ -233,6 +236,10 @@ int parse_disabled_functions(char *line) { return -1; } + if (pos) { + df->pos = atoi(pos) > 128 ? 128: atoi(pos); // FIXME do the strtol dance + } + if (df->function) { df->functions_list = parse_functions_list(df->function); } -- cgit v1.3 From 26fe379e4ed7b32084fd7b3026a713b8e26f2e29 Mon Sep 17 00:00:00 2001 From: bui Date: Tue, 17 Oct 2017 17:56:01 +0200 Subject: do the strtol dance to make jvoisin happy --- src/sp_config_keywords.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/sp_config_keywords.c') diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index 1f48852..b2e83fe 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c @@ -237,7 +237,14 @@ int parse_disabled_functions(char *line) { } if (pos) { - df->pos = atoi(pos) > 128 ? 128: atoi(pos); // FIXME do the strtol dance + errno = 0; + df->pos = strtol(pos, NULL, 10) > 128 ? 128 : strtol(pos, NULL, 10); + if (errno != 0) { + sp_log_err("config", + "Failed to parse arg '%s' of `pos` on line %zu.", + pos, sp_line_no); + return -1; + } } if (df->function) { -- cgit v1.3 From dbfe7cc04adad832d5b37ff1c6ee45767c7c648f Mon Sep 17 00:00:00 2001 From: bui Date: Tue, 17 Oct 2017 18:28:36 +0200 Subject: strtol dance --- src/sp_config_keywords.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/sp_config_keywords.c') diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index b2e83fe..cbdd579 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c @@ -238,8 +238,9 @@ int parse_disabled_functions(char *line) { if (pos) { errno = 0; - df->pos = strtol(pos, NULL, 10) > 128 ? 128 : strtol(pos, NULL, 10); - if (errno != 0) { + char *endptr; + df->pos = strtol(pos, &endptr, 10) > 128 ? 128 : strtol(pos, NULL, 10); + if (errno != 0 || endptr == pos) { sp_log_err("config", "Failed to parse arg '%s' of `pos` on line %zu.", pos, sp_line_no); -- cgit v1.3 From 765b7f81a1d157e809889c7224581db70a0ebe53 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Wed, 18 Oct 2017 00:31:18 +0200 Subject: Improve the strtol dance --- src/sp_config_keywords.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/sp_config_keywords.c') diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index cbdd579..b03c28e 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c @@ -239,13 +239,17 @@ int parse_disabled_functions(char *line) { if (pos) { errno = 0; char *endptr; - df->pos = strtol(pos, &endptr, 10) > 128 ? 128 : strtol(pos, NULL, 10); + df->pos = strtol(pos, &endptr, 10); if (errno != 0 || endptr == pos) { - sp_log_err("config", - "Failed to parse arg '%s' of `pos` on line %zu.", - pos, sp_line_no); + sp_log_err("config", "Failed to parse arg '%s' of `pos` on line %zu.", + pos, sp_line_no); return -1; } + + // We'll never have a function with more than 128 params + if (df->pos > 128) { + df->pos = 128; + } } if (df->function) { -- cgit v1.3 From 066b79abe9943821240ccc3a458e8ba45b9ee9e8 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Wed, 18 Oct 2017 17:04:44 +0200 Subject: `.pos` is mutuaally exclusive with .param and .paran_r --- src/sp_config_keywords.c | 4 ++-- src/tests/broken_conf_mutually_exclusive4.phpt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/sp_config_keywords.c') diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index b03c28e..097d08b 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c @@ -204,10 +204,10 @@ int parse_disabled_functions(char *line) { "'.r_filename' and '.filename' are mutually exclusive on line %zu.", line, sp_line_no); return -1; - } else if (df->r_param && df->param) { + } else if (1 < ((df->r_param?1:0) + (df->param?1:0) + ((-1 != df->pos)?1:0))) { sp_log_err("config", "Invalid configuration line: 'sp.disabled_functions%s':" - "'.r_param' and '.param' are mutually exclusive on line %zu.", + "'.r_param', '.param' and '.pos' are mutually exclusive on line %zu.", line, sp_line_no); return -1; } else if (df->r_ret && df->ret) { diff --git a/src/tests/broken_conf_mutually_exclusive4.phpt b/src/tests/broken_conf_mutually_exclusive4.phpt index 4e888f5..a60f3fa 100644 --- a/src/tests/broken_conf_mutually_exclusive4.phpt +++ b/src/tests/broken_conf_mutually_exclusive4.phpt @@ -6,4 +6,4 @@ Broken configuration sp.configuration_file={PWD}/config/broken_conf_mutually_exclusive4.ini --FILE-- --EXPECT-- -[snuffleupagus][0.0.0.0][config][error] Invalid configuration line: 'sp.disabled_functions.function("system").param("id").value("42").param_r("^id$").drop();':'.r_param' and '.param' are mutually exclusive on line 1. \ No newline at end of file +[snuffleupagus][0.0.0.0][config][error] Invalid configuration line: 'sp.disabled_functions.function("system").param("id").value("42").param_r("^id$").drop();':'.r_param', '.param' and '.pos' are mutually exclusive on line 1. -- cgit v1.3