diff options
| author | Julien Voisin | 2022-07-20 15:42:11 +0200 |
|---|---|---|
| committer | GitHub | 2022-07-20 15:42:11 +0200 |
| commit | 74d46c7862ef6cc4ddd7c915689f037dcf778d0e (patch) | |
| tree | 0ca89faebc81b636ea47baf40cc1a6f35dcd17ed | |
| parent | cbf0a9be15e4345bbe0da0c6be305434928ea759 (diff) | |
| parent | 27c95af26d825e33eda09f1a863443252f16e1ae (diff) | |
Merge pull request #429 from sektioneins/master
fixes+features 07/2022
| -rw-r--r-- | .gitignore | 87 | ||||
| -rw-r--r-- | Makefile | 1 | ||||
| -rw-r--r-- | doc/source/config.rst | 26 | ||||
| -rw-r--r-- | src/config.m4 | 2 | ||||
| -rw-r--r-- | src/snuffleupagus.c | 4 | ||||
| -rw-r--r-- | src/sp_config_keywords.c | 30 | ||||
| -rw-r--r-- | src/sp_execute.c | 2 |
7 files changed, 107 insertions, 45 deletions
| @@ -6,50 +6,53 @@ tags | |||
| 6 | .deps | 6 | .deps |
| 7 | .libs | 7 | .libs |
| 8 | *.lo | 8 | *.lo |
| 9 | src/tests/*.diff | 9 | *~ |
| 10 | src/tests/*.exp | ||
| 11 | src/tests/*.log | ||
| 12 | src/tests/*.out | ||
| 13 | src/tests/*.sh | ||
| 14 | src/tests/*.php | ||
| 15 | 10 | ||
| 16 | src/tests/*/*.diff | 11 | /src/tests/**/*.diff |
| 17 | src/tests/*/*.exp | 12 | /src/tests/**/*.exp |
| 18 | src/tests/*/*.log | 13 | /src/tests/**/*.log |
| 19 | src/tests/*/*.out | 14 | /src/tests/**/*.out |
| 20 | src/tests/*/*.sh | 15 | /src/tests/**/*.sh |
| 21 | src/tests/*/*.php | 16 | /src/tests/**/*.php |
| 22 | src/tests/*/phpt.* | 17 | /src/tests/**/phpt.* |
| 23 | 18 | ||
| 24 | .vscode/ | ||
| 25 | 19 | ||
| 26 | # generated by re2c or copied from cached version | 20 | # generated by re2c or copied from cached version |
| 27 | src/sp_config_scanner.c | 21 | /src/sp_config_scanner.c |
| 28 | # Files generated by phpize, configure and make | 22 | # Files generated by phpize, configure and make |
| 29 | src/autom4te.cache | 23 | /src/autom4te.cache |
| 30 | src/build | 24 | /src/build |
| 31 | src/modules | 25 | /src/modules |
| 32 | src/acinclude.m4 | 26 | /src/acinclude.m4 |
| 33 | src/aclocal.m4 | 27 | /src/aclocal.m4 |
| 34 | src/config.guess | 28 | /src/config.guess |
| 35 | src/config.h | 29 | /src/config.h |
| 36 | src/config.h.in | 30 | /src/config.h.in |
| 37 | src/config.log | 31 | /src/config.log |
| 38 | src/config.nice | 32 | /src/config.nice |
| 39 | src/config.status | 33 | /src/config.status |
| 40 | src/config.sub | 34 | /src/config.sub |
| 41 | src/configure | 35 | /src/configure |
| 42 | src/configure.in | 36 | /src/configure.in |
| 43 | src/install-sh | 37 | /src/configure.ac |
| 44 | src/*.la | 38 | /src/install-sh |
| 45 | src/ltmain.sh | 39 | /src/*.la |
| 46 | src/libtool | 40 | /src/ltmain.sh |
| 47 | src/Makefile | 41 | /src/libtool |
| 48 | src/Makefile.fragments | 42 | /src/Makefile |
| 49 | src/Makefile.global | 43 | /src/Makefile.fragments |
| 50 | src/Makefile.objects | 44 | /src/Makefile.global |
| 51 | src/missing | 45 | /src/Makefile.objects |
| 52 | src/mkinstalldirs | 46 | /src/missing |
| 53 | src/run-tests.php | 47 | /src/mkinstalldirs |
| 54 | src/*.dep | 48 | /src/run-tests.php |
| 55 | doc/build/ | 49 | /src/*.dep |
| 50 | /doc/build/ | ||
| 51 | |||
| 52 | ## development artifacts | ||
| 53 | /*.sh | ||
| 54 | /src/*.sh | ||
| 55 | /src-*/ | ||
| 56 | /src/quicktest/ | ||
| 57 | /.vscode/ | ||
| 58 | |||
| @@ -12,6 +12,7 @@ release: ## compile with releases flags | |||
| 12 | cd $(SRC); phpize | 12 | cd $(SRC); phpize |
| 13 | cd $(SRC); ./configure --enable-snuffleupagus | 13 | cd $(SRC); ./configure --enable-snuffleupagus |
| 14 | make -C $(SRC) | 14 | make -C $(SRC) |
| 15 | strip $(SRC)/.libs/snuffleupagus.so | ||
| 15 | 16 | ||
| 16 | install: release ## compile and install snuffleupagus | 17 | install: release ## compile and install snuffleupagus |
| 17 | make -C $(SRC) install | 18 | make -C $(SRC) install |
diff --git a/doc/source/config.rst b/doc/source/config.rst index d7f7f24..ac8aef1 100644 --- a/doc/source/config.rst +++ b/doc/source/config.rst | |||
| @@ -78,7 +78,7 @@ Miscellaneous | |||
| 78 | conditions | 78 | conditions |
| 79 | ^^^^^^^^^^ | 79 | ^^^^^^^^^^ |
| 80 | 80 | ||
| 81 | It's possible to use conditions to have configuration portables accross | 81 | It's possible to use conditions to have configuration portable across |
| 82 | several setups. | 82 | several setups. |
| 83 | 83 | ||
| 84 | :: | 84 | :: |
| @@ -88,6 +88,30 @@ several setups. | |||
| 88 | # some other rules | 88 | # some other rules |
| 89 | @end_condition; | 89 | @end_condition; |
| 90 | 90 | ||
| 91 | Conditions accept variables and the special function ``extension_loadod()``. | ||
| 92 | |||
| 93 | :: | ||
| 94 | @condition extension_loaded("sqlite3"); | ||
| 95 | sp.ini.key("sqlite3.extension_dir").ro(); | ||
| 96 | @end_condition; | ||
| 97 | |||
| 98 | Conditions cannot be nested, but arithmetic and logical operations can be applied. | ||
| 99 | |||
| 100 | :: | ||
| 101 | @condition extension_loaded("session") && PHP_VERSION_ID <= 80200; | ||
| 102 | set whitelist "my_fun,cos" | ||
| 103 | sp.eval_whitelist.list(whitelist).simulation().dump("/tmp/dump_result/"); | ||
| 104 | @end_condition; | ||
| 105 | |||
| 106 | variables | ||
| 107 | ^^^^^^^^^ | ||
| 108 | |||
| 109 | You may set a configuration variable using the ``set`` keyword (or ``@set``) and use it instead of arguments. | ||
| 110 | |||
| 111 | :: | ||
| 112 | @set CMD "ls" | ||
| 113 | sp.disable_function.function("system").pos("0").value(CMD).allow(); | ||
| 114 | |||
| 91 | global | 115 | global |
| 92 | ^^^^^^ | 116 | ^^^^^^ |
| 93 | 117 | ||
diff --git a/src/config.m4 b/src/config.m4 index 1958979..619dcbd 100644 --- a/src/config.m4 +++ b/src/config.m4 | |||
| @@ -31,6 +31,8 @@ CFLAGS="$CFLAGS -fstack-protector-strong" | |||
| 31 | 31 | ||
| 32 | LDFLAGS="$LDFLAGS `pcre2-config --libs8`" | 32 | LDFLAGS="$LDFLAGS `pcre2-config --libs8`" |
| 33 | 33 | ||
| 34 | AX_CHECK_COMPILE_FLAG([-Wl,-z,relro,-z,now], [LDFLAGS="$LDFLAGS -Wl,-z,relro,-z,now"], {}, [-Werror]) | ||
| 35 | |||
| 34 | if test "$PHP_DEBUG" = "yes"; then | 36 | if test "$PHP_DEBUG" = "yes"; then |
| 35 | AC_DEFINE(SP_DEBUG, 1, [Enable SP debug messages]) | 37 | AC_DEFINE(SP_DEBUG, 1, [Enable SP debug messages]) |
| 36 | CFLAGS="$CFLAGS -g -ggdb -O0" | 38 | CFLAGS="$CFLAGS -g -ggdb -O0" |
diff --git a/src/snuffleupagus.c b/src/snuffleupagus.c index 1f5b660..30f6b3d 100644 --- a/src/snuffleupagus.c +++ b/src/snuffleupagus.c | |||
| @@ -265,7 +265,7 @@ static void add_df_to_arr(zval *arr, sp_disabled_function const *const df) { | |||
| 265 | if (df->functions_list && df->functions_list->data) { | 265 | if (df->functions_list && df->functions_list->data) { |
| 266 | zval arr_fl; | 266 | zval arr_fl; |
| 267 | array_init(&arr_fl); | 267 | array_init(&arr_fl); |
| 268 | for (sp_list_node *p = df->functions_list; p; p = p->next) { add_next_index_str(&arr_fl, p->data); } | 268 | for (sp_list_node *p = df->functions_list; p; p = p->next) { add_next_index_string(&arr_fl, (char*)p->data); } |
| 269 | add_assoc_zval(&arr_df, "function_list", &arr_fl); | 269 | add_assoc_zval(&arr_df, "function_list", &arr_fl); |
| 270 | } else { | 270 | } else { |
| 271 | add_assoc_null(&arr_df, "function_list"); | 271 | add_assoc_null(&arr_df, "function_list"); |
| @@ -283,6 +283,7 @@ static void add_df_to_arr(zval *arr, sp_disabled_function const *const df) { | |||
| 283 | add_assoc_long(&arr_df, SP_TOKEN_LINE_NUMBER, df->line); | 283 | add_assoc_long(&arr_df, SP_TOKEN_LINE_NUMBER, df->line); |
| 284 | ADD_ASSOC_ZSTR(&arr_df, SP_TOKEN_RET, df->ret); | 284 | ADD_ASSOC_ZSTR(&arr_df, SP_TOKEN_RET, df->ret); |
| 285 | ADD_ASSOC_REGEXP(&arr_df, SP_TOKEN_RET_REGEXP, df->r_ret); | 285 | ADD_ASSOC_REGEXP(&arr_df, SP_TOKEN_RET_REGEXP, df->r_ret); |
| 286 | add_assoc_long(&arr_df, SP_TOKEN_RET_TYPE, df->ret_type); | ||
| 286 | ADD_ASSOC_ZSTR(&arr_df, SP_TOKEN_VALUE, df->value); | 287 | ADD_ASSOC_ZSTR(&arr_df, SP_TOKEN_VALUE, df->value); |
| 287 | ADD_ASSOC_REGEXP(&arr_df, SP_TOKEN_VALUE_REGEXP, df->r_value); | 288 | ADD_ASSOC_REGEXP(&arr_df, SP_TOKEN_VALUE_REGEXP, df->r_value); |
| 288 | ADD_ASSOC_ZSTR(&arr_df, SP_TOKEN_KEY, df->key); | 289 | ADD_ASSOC_ZSTR(&arr_df, SP_TOKEN_KEY, df->key); |
| @@ -495,6 +496,7 @@ static PHP_INI_MH(OnUpdateConfiguration) { | |||
| 495 | 496 | ||
| 496 | // set some defaults | 497 | // set some defaults |
| 497 | SPCFG(show_old_php_warning) = true; | 498 | SPCFG(show_old_php_warning) = true; |
| 499 | SPCFG(readonly_exec).extended_checks = true; | ||
| 498 | 500 | ||
| 499 | char *str = new_value->val; | 501 | char *str = new_value->val; |
| 500 | 502 | ||
diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index ea4e1cd..fa26635 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c | |||
| @@ -228,9 +228,32 @@ SP_PARSE_FN(parse_cookie) { | |||
| 228 | ZSTR_VAL(samesite), parsed_rule->lineno); | 228 | ZSTR_VAL(samesite), parsed_rule->lineno); |
| 229 | goto err; | 229 | goto err; |
| 230 | } | 230 | } |
| 231 | zend_string_release(samesite); | ||
| 232 | samesite = NULL; | ||
| 231 | } | 233 | } |
| 232 | 234 | ||
| 233 | SPCFG(cookie).cookies = sp_list_insert(SPCFG(cookie).cookies, cookie); | 235 | // find other cookie entry with identical name or name_r |
| 236 | sp_cookie *entry = NULL; | ||
| 237 | sp_list_node *pList = NULL; | ||
| 238 | for (pList = SPCFG(cookie).cookies; pList; pList = pList->next) { | ||
| 239 | entry = pList->data; | ||
| 240 | if (!entry) { continue; } | ||
| 241 | if ((entry->name && cookie->name && sp_zend_string_equals(entry->name, cookie->name)) || | ||
| 242 | (entry->name_r && cookie->name_r && sp_zend_string_equals(entry->name_r->pattern, cookie->name_r->pattern))) { | ||
| 243 | break; | ||
| 244 | } | ||
| 245 | } | ||
| 246 | if (pList && entry) { | ||
| 247 | // override cookie settings if set | ||
| 248 | if (cookie->samesite) { entry->samesite = cookie->samesite; } | ||
| 249 | if (cookie->encrypt) { entry->encrypt = cookie->encrypt; } | ||
| 250 | if (cookie->simulation) { entry->simulation = cookie->simulation; } | ||
| 251 | sp_free_cookie(cookie); | ||
| 252 | pefree(cookie, 1); | ||
| 253 | cookie = NULL; | ||
| 254 | } else { | ||
| 255 | SPCFG(cookie).cookies = sp_list_insert(SPCFG(cookie).cookies, cookie); | ||
| 256 | } | ||
| 234 | 257 | ||
| 235 | return SP_PARSER_STOP; | 258 | return SP_PARSER_STOP; |
| 236 | 259 | ||
| @@ -492,6 +515,11 @@ SP_PARSE_FN(parse_ini_entry) { | |||
| 492 | goto err; | 515 | goto err; |
| 493 | } | 516 | } |
| 494 | 517 | ||
| 518 | if (zend_hash_find_ptr(SPCFG(ini).entries, entry->key)) { | ||
| 519 | sp_log_err("config", "duplicate INI key '%s' on line %zu", ZSTR_VAL(entry->key), parsed_rule->lineno); | ||
| 520 | goto err; | ||
| 521 | } | ||
| 522 | |||
| 495 | if (ro && rw) { | 523 | if (ro && rw) { |
| 496 | sp_log_err("config", "rule cannot be both read-write and read-only on line %zu", parsed_rule->lineno); | 524 | sp_log_err("config", "rule cannot be both read-write and read-only on line %zu", parsed_rule->lineno); |
| 497 | goto err; | 525 | goto err; |
diff --git a/src/sp_execute.c b/src/sp_execute.c index 81614f3..b4e5c6c 100644 --- a/src/sp_execute.c +++ b/src/sp_execute.c | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | #include "php_snuffleupagus.h" | 1 | #include "php_snuffleupagus.h" |
| 2 | #include "ext/standard/php_string.h" | ||
| 2 | 3 | ||
| 3 | static void (*orig_execute_ex)(zend_execute_data *execute_data) = NULL; | 4 | static void (*orig_execute_ex)(zend_execute_data *execute_data) = NULL; |
| 4 | static void (*orig_zend_execute_internal)(zend_execute_data *execute_data, | 5 | static void (*orig_zend_execute_internal)(zend_execute_data *execute_data, |
| @@ -40,6 +41,7 @@ ZEND_COLD static inline void terminate_if_writable(char const* const filename) { | |||
| 40 | php_dirname(dirname, strlen(dirname)); | 41 | php_dirname(dirname, strlen(dirname)); |
| 41 | if (0 == access(dirname, W_OK)) { | 42 | if (0 == access(dirname, W_OK)) { |
| 42 | errmsg = "Attempted execution of a file in a writable directory"; | 43 | errmsg = "Attempted execution of a file in a writable directory"; |
| 44 | |||
| 43 | efree(dirname); | 45 | efree(dirname); |
| 44 | goto violation; | 46 | goto violation; |
| 45 | } | 47 | } |
