diff options
| author | jvoisin | 2017-12-04 16:09:50 +0100 |
|---|---|---|
| committer | jvoisin | 2017-12-04 16:09:50 +0100 |
| commit | 32476340c5fd3c76b86487a92fd5c5075342ca99 (patch) | |
| tree | 0d5de876ae0d3e19544dfcbb3454218aa8654aac /src | |
| parent | 2e9d73756cff850569bdbf563815f9f3f3ded06e (diff) | |
Fix the configuration parser wrt. non-matching brackets
This validation step is a bit idiotic, but we'll replace it with a
proper parser anyway.
Diffstat (limited to 'src')
| -rw-r--r-- | src/sp_config_utils.c | 9 | ||||
| -rw-r--r-- | src/tests/broken_conf_quotes.phpt | 9 | ||||
| -rw-r--r-- | src/tests/broken_regexp.phpt | 1 | ||||
| -rw-r--r-- | src/tests/config/broken_conf_quotes.ini | 3 | ||||
| -rw-r--r-- | src/tests/example_configuration.phpt | 2 |
5 files changed, 21 insertions, 3 deletions
diff --git a/src/sp_config_utils.c b/src/sp_config_utils.c index 71dd373..1a797e5 100644 --- a/src/sp_config_utils.c +++ b/src/sp_config_utils.c | |||
| @@ -20,7 +20,12 @@ static int validate_str(const char *value) { | |||
| 20 | return -1; | 20 | return -1; |
| 21 | } | 21 | } |
| 22 | } | 22 | } |
| 23 | return balance != 0; | 23 | if (balance != 0) { |
| 24 | sp_log_err("config", "You forgot to close %d bracket%c in the string '%s'", | ||
| 25 | balance, (balance>1)?'s':' ', value); | ||
| 26 | return -1; | ||
| 27 | } | ||
| 28 | return 0; | ||
| 24 | } | 29 | } |
| 25 | 30 | ||
| 26 | int parse_keywords(sp_config_functions *funcs, char *line) { | 31 | int parse_keywords(sp_config_functions *funcs, char *line) { |
| @@ -112,7 +117,7 @@ err: | |||
| 112 | sp_log_err("error", | 117 | sp_log_err("error", |
| 113 | "There is an issue with the parsing of '%s': it doesn't look like a valid string on line %zu.", | 118 | "There is an issue with the parsing of '%s': it doesn't look like a valid string on line %zu.", |
| 114 | original_line ? original_line : "NULL", sp_line_no); | 119 | original_line ? original_line : "NULL", sp_line_no); |
| 115 | } | 120 | } |
| 116 | line = NULL; | 121 | line = NULL; |
| 117 | return NULL; | 122 | return NULL; |
| 118 | } | 123 | } |
diff --git a/src/tests/broken_conf_quotes.phpt b/src/tests/broken_conf_quotes.phpt new file mode 100644 index 0000000..7f754e6 --- /dev/null +++ b/src/tests/broken_conf_quotes.phpt | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | --TEST-- | ||
| 2 | Broken configuration - missing quote | ||
| 3 | --SKIPIF-- | ||
| 4 | <?php if (!extension_loaded("snuffleupagus")) print "skip"; ?> | ||
| 5 | --INI-- | ||
| 6 | sp.configuration_file={PWD}/config/broken_conf_quotes.ini | ||
| 7 | --FILE-- | ||
| 8 | --EXPECT-- | ||
| 9 | [snuffleupagus][0.0.0.0][config][error] You forgot to close 1 bracket in the string '_SERVER[PHP_SELF' | ||
diff --git a/src/tests/broken_regexp.phpt b/src/tests/broken_regexp.phpt index 3367997..680cf22 100644 --- a/src/tests/broken_regexp.phpt +++ b/src/tests/broken_regexp.phpt | |||
| @@ -6,4 +6,5 @@ Broken regexp | |||
| 6 | sp.configuration_file={PWD}/config/broken_regexp.ini | 6 | sp.configuration_file={PWD}/config/broken_regexp.ini |
| 7 | --FILE-- | 7 | --FILE-- |
| 8 | --EXPECTF-- | 8 | --EXPECTF-- |
| 9 | [snuffleupagus][0.0.0.0][config][error] You forgot to close 1 bracket in the string '^$[' | ||
| 9 | [snuffleupagus][0.0.0.0][config][error] '.value_r()' is expecting a valid regexp, and not '"^$["' on line 1. | 10 | [snuffleupagus][0.0.0.0][config][error] '.value_r()' is expecting a valid regexp, and not '"^$["' on line 1. |
diff --git a/src/tests/config/broken_conf_quotes.ini b/src/tests/config/broken_conf_quotes.ini new file mode 100644 index 0000000..7c3b0cd --- /dev/null +++ b/src/tests/config/broken_conf_quotes.ini | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | sp.disable_function.filename("static_pages/index.php").var("_SERVER[PHP_SELF").value_r("\"").drop().alias("XSS"); | ||
| 2 | sp.disable_function.filename("include/imageobject_im.class.php").function("exec").var("CONFIG[im_options]).value_r("[^a-z0-9]").drop(); | ||
| 3 | |||
diff --git a/src/tests/example_configuration.phpt b/src/tests/example_configuration.phpt index 0bbf59c..b7fec48 100644 --- a/src/tests/example_configuration.phpt +++ b/src/tests/example_configuration.phpt | |||
| @@ -6,7 +6,7 @@ Shipped configuration | |||
| 6 | sp.configuration_file={PWD}/../../config/examples.ini | 6 | sp.configuration_file={PWD}/../../config/examples.ini |
| 7 | --FILE-- | 7 | --FILE-- |
| 8 | <?php | 8 | <?php |
| 9 | system("echo 0"); | 9 | echo 0; |
| 10 | ?> | 10 | ?> |
| 11 | --EXPECTF-- | 11 | --EXPECTF-- |
| 12 | 0 | 12 | 0 |
