summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjvoisin2017-10-10 14:47:56 +0200
committerjvoisin2017-10-10 14:47:56 +0200
commitef1cb7661ed577039c7fa6caea7490330237f091 (patch)
tree4ac7652b259a99cec284bc8929f2b75fde4112b8
parent6c458dcf33ae2b1fb17bf9104ab0bb4fa6f23910 (diff)
Bump coverage, and fix a segfault on trace matching
-rw-r--r--src/sp_config_keywords.c13
-rw-r--r--src/sp_disabled_functions.c13
-rw-r--r--src/tests/broken_conf_no_cookie_name.phpt9
-rw-r--r--src/tests/config/config_disabled_functions_chain.ini2
-rw-r--r--src/tests/config/config_encrypted_cookies_noname.ini3
5 files changed, 33 insertions, 7 deletions
diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c
index 8fba868..e71463a 100644
--- a/src/sp_config_keywords.c
+++ b/src/sp_config_keywords.c
@@ -128,13 +128,16 @@ int parse_cookie_encryption(char *line) {
128 "on line %zu without having set the `.encryption_key` option in" 128 "on line %zu without having set the `.encryption_key` option in"
129 "`sp.global`: please set it first.", sp_line_no); 129 "`sp.global`: please set it first.", sp_line_no);
130 return -1; 130 return -1;
131 } else if (0 == strlen(name)) {
132 sp_log_err("config", "You must specify a cookie name to encrypt on line "
133 "%zu.", sp_line_no);
134 return -1;
131 } 135 }
132 136
133 if (name) { 137 zend_hash_str_add_empty_element(
134 zend_hash_str_add_empty_element( 138 SNUFFLEUPAGUS_G(config).config_cookie_encryption->names, name,
135 SNUFFLEUPAGUS_G(config).config_cookie_encryption->names, name, 139 strlen(name));
136 strlen(name)); 140
137 }
138 return SUCCESS; 141 return SUCCESS;
139} 142}
140 143
diff --git a/src/sp_disabled_functions.c b/src/sp_disabled_functions.c
index b465a30..e4ba19a 100644
--- a/src/sp_disabled_functions.c
+++ b/src/sp_disabled_functions.c
@@ -15,6 +15,11 @@ ZEND_COLD static zend_always_inline bool is_hash_matching(
15 15
16static zend_always_inline char* get_complete_function_path( 16static zend_always_inline char* get_complete_function_path(
17 zend_execute_data const* const execute_data) { 17 zend_execute_data const* const execute_data) {
18
19 if (!(execute_data->func->common.function_name)) {
20 return NULL;
21 }
22
18 char const* class_name; 23 char const* class_name;
19 char const* const function_name = 24 char const* const function_name =
20 ZSTR_VAL(execute_data->func->common.function_name); 25 ZSTR_VAL(execute_data->func->common.function_name);
@@ -38,12 +43,16 @@ static bool is_functions_list_matching(zend_execute_data *execute_data, sp_node_
38 43
39 while (current) { 44 while (current) {
40 if (it == NULL) { // every function in the list matched, we've got a match! 45 if (it == NULL) { // every function in the list matched, we've got a match!
46 EG(current_execute_data) = orig_execute_data;
41 return true; 47 return true;
42 } 48 }
43 49
44 EG(current_execute_data) = current; 50 EG(current_execute_data) = current;
45 51
46 char *complete_path_function = get_complete_function_path(current); 52 char *complete_path_function = get_complete_function_path(current);
53 if (!complete_path_function) {
54 goto end;
55 }
47 int match = strcmp(((char*)it->data), complete_path_function); 56 int match = strcmp(((char*)it->data), complete_path_function);
48 efree(complete_path_function); 57 efree(complete_path_function);
49 58
@@ -51,11 +60,11 @@ static bool is_functions_list_matching(zend_execute_data *execute_data, sp_node_
51 it = it->next; 60 it = it->next;
52 current = current->prev_execute_data; 61 current = current->prev_execute_data;
53 } else { 62 } else {
54 EG(current_execute_data) = orig_execute_data; 63 goto end;
55 return false;
56 } 64 }
57 } 65 }
58 66
67end:
59 EG(current_execute_data) = orig_execute_data; 68 EG(current_execute_data) = orig_execute_data;
60 return false; 69 return false;
61} 70}
diff --git a/src/tests/broken_conf_no_cookie_name.phpt b/src/tests/broken_conf_no_cookie_name.phpt
new file mode 100644
index 0000000..feaf6ca
--- /dev/null
+++ b/src/tests/broken_conf_no_cookie_name.phpt
@@ -0,0 +1,9 @@
1--TEST--
2Borken configuration - encrypted cookie with no name
3--SKIPIF--
4<?php if (!extension_loaded("snuffleupagus")) print "skip"; ?>
5--INI--
6sp.configuration_file={PWD}/config/config_encrypted_cookies_noname.ini
7--FILE--
8--EXPECT--
9[snuffleupagus][0.0.0.0][config][error] You must specify a cookie name to encrypt on line 2.
diff --git a/src/tests/config/config_disabled_functions_chain.ini b/src/tests/config/config_disabled_functions_chain.ini
index f47af34..5eacbc3 100644
--- a/src/tests/config/config_disabled_functions_chain.ini
+++ b/src/tests/config/config_disabled_functions_chain.ini
@@ -1 +1,3 @@
1sp.disable_functions.function("outer>inner>other").drop();
2sp.disable_functions.function("other>outer>inner_").drop();
1sp.disable_functions.function("outer>inner").drop(); 3sp.disable_functions.function("outer>inner").drop();
diff --git a/src/tests/config/config_encrypted_cookies_noname.ini b/src/tests/config/config_encrypted_cookies_noname.ini
new file mode 100644
index 0000000..27773e3
--- /dev/null
+++ b/src/tests/config/config_encrypted_cookies_noname.ini
@@ -0,0 +1,3 @@
1sp.global.secret_key("abcdef").cookie_env_var("REMOTE_ADDR");
2sp.cookie_encryption.cookie("");
3sp.auto_cookie_secure.enable();