summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Voisin2022-07-20 15:42:11 +0200
committerGitHub2022-07-20 15:42:11 +0200
commit74d46c7862ef6cc4ddd7c915689f037dcf778d0e (patch)
tree0ca89faebc81b636ea47baf40cc1a6f35dcd17ed
parentcbf0a9be15e4345bbe0da0c6be305434928ea759 (diff)
parent27c95af26d825e33eda09f1a863443252f16e1ae (diff)
Merge pull request #429 from sektioneins/master
fixes+features 07/2022
-rw-r--r--.gitignore87
-rw-r--r--Makefile1
-rw-r--r--doc/source/config.rst26
-rw-r--r--src/config.m42
-rw-r--r--src/snuffleupagus.c4
-rw-r--r--src/sp_config_keywords.c30
-rw-r--r--src/sp_execute.c2
7 files changed, 107 insertions, 45 deletions
diff --git a/.gitignore b/.gitignore
index e4986e9..c47ec1c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,50 +6,53 @@ tags
6.deps 6.deps
7.libs 7.libs
8*.lo 8*.lo
9src/tests/*.diff 9*~
10src/tests/*.exp
11src/tests/*.log
12src/tests/*.out
13src/tests/*.sh
14src/tests/*.php
15 10
16src/tests/*/*.diff 11/src/tests/**/*.diff
17src/tests/*/*.exp 12/src/tests/**/*.exp
18src/tests/*/*.log 13/src/tests/**/*.log
19src/tests/*/*.out 14/src/tests/**/*.out
20src/tests/*/*.sh 15/src/tests/**/*.sh
21src/tests/*/*.php 16/src/tests/**/*.php
22src/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
27src/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
29src/autom4te.cache 23/src/autom4te.cache
30src/build 24/src/build
31src/modules 25/src/modules
32src/acinclude.m4 26/src/acinclude.m4
33src/aclocal.m4 27/src/aclocal.m4
34src/config.guess 28/src/config.guess
35src/config.h 29/src/config.h
36src/config.h.in 30/src/config.h.in
37src/config.log 31/src/config.log
38src/config.nice 32/src/config.nice
39src/config.status 33/src/config.status
40src/config.sub 34/src/config.sub
41src/configure 35/src/configure
42src/configure.in 36/src/configure.in
43src/install-sh 37/src/configure.ac
44src/*.la 38/src/install-sh
45src/ltmain.sh 39/src/*.la
46src/libtool 40/src/ltmain.sh
47src/Makefile 41/src/libtool
48src/Makefile.fragments 42/src/Makefile
49src/Makefile.global 43/src/Makefile.fragments
50src/Makefile.objects 44/src/Makefile.global
51src/missing 45/src/Makefile.objects
52src/mkinstalldirs 46/src/missing
53src/run-tests.php 47/src/mkinstalldirs
54src/*.dep 48/src/run-tests.php
55doc/build/ 49/src/*.dep
50/doc/build/
51
52## development artifacts
53/*.sh
54/src/*.sh
55/src-*/
56/src/quicktest/
57/.vscode/
58
diff --git a/Makefile b/Makefile
index 51c6cc9..6d5b004 100644
--- a/Makefile
+++ b/Makefile
@@ -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
16install: release ## compile and install snuffleupagus 17install: 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
78conditions 78conditions
79^^^^^^^^^^ 79^^^^^^^^^^
80 80
81It's possible to use conditions to have configuration portables accross 81It's possible to use conditions to have configuration portable across
82several setups. 82several 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
91Conditions 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
98Conditions 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
106variables
107^^^^^^^^^
108
109You 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
91global 115global
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
32LDFLAGS="$LDFLAGS `pcre2-config --libs8`" 32LDFLAGS="$LDFLAGS `pcre2-config --libs8`"
33 33
34AX_CHECK_COMPILE_FLAG([-Wl,-z,relro,-z,now], [LDFLAGS="$LDFLAGS -Wl,-z,relro,-z,now"], {}, [-Werror])
35
34if test "$PHP_DEBUG" = "yes"; then 36if 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
3static void (*orig_execute_ex)(zend_execute_data *execute_data) = NULL; 4static void (*orig_execute_ex)(zend_execute_data *execute_data) = NULL;
4static void (*orig_zend_execute_internal)(zend_execute_data *execute_data, 5static 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 }