summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjvoisin2017-12-21 14:03:18 +0100
committerjvoisin2017-12-21 14:03:18 +0100
commit0d98f51e7dbde4a40c0039910d43ad378eaefa83 (patch)
tree78749747bc46c80f85bc2c3cdfb629b331d200f1 /src
parentf91cf7390c060986e51b77990f4e472165b97dad (diff)
Rename sp_node_t to sp_list_node
Since we now have sp_list and sp_tree, it makes sense to specify that nodes are only for lists.
Diffstat (limited to 'src')
-rw-r--r--src/snuffleupagus.c2
-rw-r--r--src/sp_config.c4
-rw-r--r--src/sp_config.h16
-rw-r--r--src/sp_config_utils.c4
-rw-r--r--src/sp_config_utils.h4
-rw-r--r--src/sp_disabled_functions.c12
-rw-r--r--src/sp_execute.c6
-rw-r--r--src/sp_list.c24
-rw-r--r--src/sp_list.h12
-rw-r--r--src/sp_var_parser.c10
10 files changed, 47 insertions, 47 deletions
diff --git a/src/snuffleupagus.c b/src/snuffleupagus.c
index bf18588..ae1a864 100644
--- a/src/snuffleupagus.c
+++ b/src/snuffleupagus.c
@@ -111,7 +111,7 @@ PHP_MSHUTDOWN_FUNCTION(snuffleupagus) {
111 111
112#define FREE_LST(L) \ 112#define FREE_LST(L) \
113 do { \ 113 do { \
114 sp_node_t* _n = SNUFFLEUPAGUS_G(L); \ 114 sp_list_node* _n = SNUFFLEUPAGUS_G(L); \
115 sp_disabled_function_list_free(_n); \ 115 sp_disabled_function_list_free(_n); \
116 sp_list_free(_n); \ 116 sp_list_free(_n); \
117 } while(0) 117 } while(0)
diff --git a/src/sp_config.c b/src/sp_config.c
index bed81bc..1877859 100644
--- a/src/sp_config.c
+++ b/src/sp_config.c
@@ -183,8 +183,8 @@ int sp_parse_config(const char *conf_file) {
183 return SUCCESS; 183 return SUCCESS;
184} 184}
185 185
186void sp_disabled_function_list_free(sp_node_t* list) { 186void sp_disabled_function_list_free(sp_list_node* list) {
187 sp_node_t* cursor = list; 187 sp_list_node* cursor = list;
188 while(cursor) { 188 while(cursor) {
189 sp_disabled_function* df = cursor->data; 189 sp_disabled_function* df = cursor->data;
190 if (df && df->functions_list) 190 if (df && df->functions_list)
diff --git a/src/sp_config.h b/src/sp_config.h
index 127c557..86513f9 100644
--- a/src/sp_config.h
+++ b/src/sp_config.h
@@ -73,7 +73,7 @@ typedef struct {
73 73
74 char *function; 74 char *function;
75 pcre *r_function; 75 pcre *r_function;
76 sp_node_t *functions_list; 76 sp_list_node *functions_list;
77 77
78 char *hash; 78 char *hash;
79 int simulation; 79 int simulation;
@@ -98,8 +98,8 @@ typedef struct {
98 char *alias; 98 char *alias;
99 bool param_is_array; 99 bool param_is_array;
100 bool var_is_array; 100 bool var_is_array;
101 sp_node_t *param_array_keys; 101 sp_list_node *param_array_keys;
102 sp_node_t *var_array_keys; 102 sp_list_node *var_array_keys;
103 103
104 bool allow; 104 bool allow;
105 105
@@ -109,7 +109,7 @@ typedef struct {
109} sp_disabled_function; 109} sp_disabled_function;
110 110
111typedef struct { 111typedef struct {
112 sp_node_t *disabled_functions; // list of sp_disabled_function 112 sp_list_node *disabled_functions; // list of sp_disabled_function
113} sp_config_disabled_functions; 113} sp_config_disabled_functions;
114 114
115typedef struct { 115typedef struct {
@@ -117,9 +117,9 @@ typedef struct {
117} sp_config_cookie; 117} sp_config_cookie;
118 118
119typedef struct { 119typedef struct {
120 sp_node_t *construct_include; // list of rules for `(include|require)_(once)?` 120 sp_list_node *construct_include; // list of rules for `(include|require)_(once)?`
121 sp_node_t *construct_eval; 121 sp_list_node *construct_eval;
122 sp_node_t *construct_echo; 122 sp_list_node *construct_echo;
123} sp_config_disabled_constructs; 123} sp_config_disabled_constructs;
124 124
125typedef struct { 125typedef struct {
@@ -227,6 +227,6 @@ int parse_cidr(char *restrict, char *restrict, void *);
227int parse_php_type(char *restrict, char *restrict, void *); 227int parse_php_type(char *restrict, char *restrict, void *);
228 228
229// cleanup 229// cleanup
230void sp_disabled_function_list_free(sp_node_t*); 230void sp_disabled_function_list_free(sp_list_node*);
231 231
232#endif /* SP_CONFIG_H */ 232#endif /* SP_CONFIG_H */
diff --git a/src/sp_config_utils.c b/src/sp_config_utils.c
index ddd2e05..3c1d89d 100644
--- a/src/sp_config_utils.c
+++ b/src/sp_config_utils.c
@@ -133,14 +133,14 @@ char *get_param(size_t *consumed, char *restrict line, sp_type type,
133 return NULL; 133 return NULL;
134} 134}
135 135
136zend_always_inline sp_node_t *parse_functions_list(char *value) { 136zend_always_inline sp_list_node *parse_functions_list(char *value) {
137 const char *sep = ">"; 137 const char *sep = ">";
138 138
139 if (NULL == strchr(value, sep[0])) { 139 if (NULL == strchr(value, sep[0])) {
140 return NULL; 140 return NULL;
141 } 141 }
142 142
143 sp_node_t *list = sp_list_new(); 143 sp_list_node *list = sp_list_new();
144 char* tmp = strdup(value); 144 char* tmp = strdup(value);
145 char* function_name; 145 char* function_name;
146 char *next_token = tmp; 146 char *next_token = tmp;
diff --git a/src/sp_config_utils.h b/src/sp_config_utils.h
index e561d57..9fef996 100644
--- a/src/sp_config_utils.h
+++ b/src/sp_config_utils.h
@@ -3,7 +3,7 @@
3 3
4int parse_keywords(sp_config_functions *, char *); 4int parse_keywords(sp_config_functions *, char *);
5char *get_param(size_t *, char *restrict, sp_type, const char *restrict); 5char *get_param(size_t *, char *restrict, sp_type, const char *restrict);
6int array_to_list(char **, sp_node_t **); 6int array_to_list(char **, sp_list_node **);
7sp_node_t *parse_functions_list(char *value); 7sp_list_node *parse_functions_list(char *value);
8 8
9#endif /* SP_CONFIG_UTILS */ 9#endif /* SP_CONFIG_UTILS */
diff --git a/src/sp_disabled_functions.c b/src/sp_disabled_functions.c
index c7974ff..18545c0 100644
--- a/src/sp_disabled_functions.c
+++ b/src/sp_disabled_functions.c
@@ -28,10 +28,10 @@ static char* get_complete_function_path(
28} 28}
29 29
30static bool is_functions_list_matching(zend_execute_data* execute_data, 30static bool is_functions_list_matching(zend_execute_data* execute_data,
31 sp_node_t* functions_list) { 31 sp_list_node* functions_list) {
32 zend_execute_data *orig_execute_data, *current; 32 zend_execute_data *orig_execute_data, *current;
33 orig_execute_data = current = execute_data; 33 orig_execute_data = current = execute_data;
34 sp_node_t* it = functions_list; 34 sp_list_node* it = functions_list;
35 35
36 while (current) { 36 while (current) {
37 if (it == NULL) { // every function in the list matched, we've got a match! 37 if (it == NULL) { // every function in the list matched, we've got a match!
@@ -91,7 +91,7 @@ static bool is_local_var_matching(
91 return false; 91 return false;
92} 92}
93 93
94static const sp_node_t* get_config_node(const char* builtin_name) { 94static const sp_list_node* get_config_node(const char* builtin_name) {
95 if (!builtin_name) { 95 if (!builtin_name) {
96 return SNUFFLEUPAGUS_G(config) 96 return SNUFFLEUPAGUS_G(config)
97 .config_disabled_functions->disabled_functions; 97 .config_disabled_functions->disabled_functions;
@@ -214,7 +214,7 @@ static bool is_param_matching(zend_execute_data* execute_data,
214bool should_disable(zend_execute_data* execute_data, const char* builtin_name, 214bool should_disable(zend_execute_data* execute_data, const char* builtin_name,
215 const char* builtin_param, const char* builtin_param_name) { 215 const char* builtin_param, const char* builtin_param_name) {
216 char current_file_hash[SHA256_SIZE * 2 + 1] = {0}; 216 char current_file_hash[SHA256_SIZE * 2 + 1] = {0};
217 const sp_node_t* config = get_config_node(builtin_name); 217 const sp_list_node* config = get_config_node(builtin_name);
218 char* complete_path_function = get_complete_function_path(execute_data); 218 char* complete_path_function = get_complete_function_path(execute_data);
219 char const* client_ip = getenv("REMOTE_ADDR"); 219 char const* client_ip = getenv("REMOTE_ADDR");
220 const char* current_filename; 220 const char* current_filename;
@@ -341,7 +341,7 @@ allow:
341 341
342static bool should_drop_on_ret(zval* return_value, 342static bool should_drop_on_ret(zval* return_value,
343 const zend_execute_data* const execute_data) { 343 const zend_execute_data* const execute_data) {
344 const sp_node_t* config = 344 const sp_list_node* config =
345 SNUFFLEUPAGUS_G(config).config_disabled_functions_ret->disabled_functions; 345 SNUFFLEUPAGUS_G(config).config_disabled_functions_ret->disabled_functions;
346 char* complete_path_function = get_complete_function_path(execute_data); 346 char* complete_path_function = get_complete_function_path(execute_data);
347 const char* current_filename = zend_get_executed_filename(TSRMLS_C); 347 const char* current_filename = zend_get_executed_filename(TSRMLS_C);
@@ -445,7 +445,7 @@ ZEND_FUNCTION(check_disabled_function) {
445 } 445 }
446} 446}
447 447
448static int hook_functions(const sp_node_t* config) { 448static int hook_functions(const sp_list_node* config) {
449 while (config && config->data) { 449 while (config && config->data) {
450 const char* function_name = ((sp_disabled_function*)config->data)->function; 450 const char* function_name = ((sp_disabled_function*)config->data)->function;
451 const pcre* function_name_regexp = 451 const pcre* function_name_regexp =
diff --git a/src/sp_execute.c b/src/sp_execute.c
index cd9ee99..2a62fd8 100644
--- a/src/sp_execute.c
+++ b/src/sp_execute.c
@@ -29,7 +29,7 @@ ZEND_COLD static inline void terminate_if_writable(const char *filename) {
29} 29}
30 30
31static void is_builtin_matching(const char * restrict const filename, 31static void is_builtin_matching(const char * restrict const filename,
32 char* restrict function_name, char* restrict param_name, sp_node_t *config) { 32 char* restrict function_name, char* restrict param_name, sp_list_node *config) {
33 if (!config || !config->data) { 33 if (!config || !config->data) {
34 return; 34 return;
35 } 35 }
@@ -65,7 +65,7 @@ static void sp_execute_ex(zend_execute_data *execute_data) {
65 } 65 }
66 66
67 if (execute_data->func->op_array.type == ZEND_EVAL_CODE) { 67 if (execute_data->func->op_array.type == ZEND_EVAL_CODE) {
68 sp_node_t* config = SNUFFLEUPAGUS_G(config).config_disabled_constructs->construct_eval; 68 sp_list_node* config = SNUFFLEUPAGUS_G(config).config_disabled_constructs->construct_eval;
69 char *filename = get_eval_filename((char *)zend_get_executed_filename()); 69 char *filename = get_eval_filename((char *)zend_get_executed_filename());
70 is_builtin_matching(filename, "eval", NULL, config); 70 is_builtin_matching(filename, "eval", NULL, config);
71 efree(filename); 71 efree(filename);
@@ -92,7 +92,7 @@ static int sp_stream_open(const char *filename, zend_file_handle *handle) {
92 if (true == SNUFFLEUPAGUS_G(config).config_readonly_exec->enable) { 92 if (true == SNUFFLEUPAGUS_G(config).config_readonly_exec->enable) {
93 terminate_if_writable(filename); 93 terminate_if_writable(filename);
94 } 94 }
95 sp_node_t* config = SNUFFLEUPAGUS_G(config).config_disabled_constructs->construct_include; 95 sp_list_node* config = SNUFFLEUPAGUS_G(config).config_disabled_constructs->construct_include;
96 switch (data->opline->extended_value) { 96 switch (data->opline->extended_value) {
97 case ZEND_INCLUDE: 97 case ZEND_INCLUDE:
98 is_builtin_matching(filename, "include", "inclusion path", config); 98 is_builtin_matching(filename, "include", "inclusion path", config);
diff --git a/src/sp_list.c b/src/sp_list.c
index 70d0ebe..2a9d680 100644
--- a/src/sp_list.c
+++ b/src/sp_list.c
@@ -3,35 +3,35 @@
3#include <stdlib.h> 3#include <stdlib.h>
4#include "php_snuffleupagus.h" 4#include "php_snuffleupagus.h"
5 5
6void sp_list_free(sp_node_t *node) { 6void sp_list_free(sp_list_node *node) {
7 while(node) { 7 while(node) {
8 sp_node_t *tmp = node->next; 8 sp_list_node *tmp = node->next;
9 pefree(node, 1); 9 pefree(node, 1);
10 node = tmp; 10 node = tmp;
11 } 11 }
12} 12}
13 13
14sp_node_t *sp_list_new() { 14sp_list_node *sp_list_new() {
15 sp_node_t *new = pecalloc(sizeof(*new), 1, 1); 15 sp_list_node *new = pecalloc(sizeof(*new), 1, 1);
16 new->next = new->data = new->head = NULL; 16 new->next = new->data = new->head = NULL;
17 return new; 17 return new;
18} 18}
19 19
20// Thanks to https://en.wikipedia.org/wiki/Insertion_sort :> 20// Thanks to https://en.wikipedia.org/wiki/Insertion_sort :>
21sp_node_t *sp_list_sort(sp_node_t *pList, int (*cmp_func)(sp_node_t *, sp_node_t *)) { 21sp_list_node *sp_list_sort(sp_list_node *pList, int (*cmp_func)(sp_list_node *, sp_list_node *)) {
22 sp_node_t *head = NULL; 22 sp_list_node *head = NULL;
23 23
24 if (pList == NULL || pList->next == NULL) { 24 if (pList == NULL || pList->next == NULL) {
25 return pList; 25 return pList;
26 } 26 }
27 while (pList != NULL) { 27 while (pList != NULL) {
28 sp_node_t *current = pList; 28 sp_list_node *current = pList;
29 pList = pList->next; 29 pList = pList->next;
30 if (head == NULL || 0 > cmp_func(current, head)) { 30 if (head == NULL || 0 > cmp_func(current, head)) {
31 current->next = head; 31 current->next = head;
32 head = current; 32 head = current;
33 } else { 33 } else {
34 sp_node_t *p = head; 34 sp_list_node *p = head;
35 while (p != NULL) { 35 while (p != NULL) {
36 if (p->next == NULL || 0 > cmp_func(current, p->next)) { 36 if (p->next == NULL || 0 > cmp_func(current, p->next)) {
37 current->next = p->next; 37 current->next = p->next;
@@ -45,13 +45,13 @@ sp_node_t *sp_list_sort(sp_node_t *pList, int (*cmp_func)(sp_node_t *, sp_node_t
45 return head; 45 return head;
46} 46}
47 47
48void sp_list_insert(sp_node_t *list, void *data) { 48void sp_list_insert(sp_list_node *list, void *data) {
49 if (list->head == NULL) { 49 if (list->head == NULL) {
50 list->data = data; 50 list->data = data;
51 list->next = NULL; 51 list->next = NULL;
52 list->head = list; 52 list->head = list;
53 } else { 53 } else {
54 sp_node_t *new = pecalloc(sizeof(*new), 1, 1); 54 sp_list_node *new = pecalloc(sizeof(*new), 1, 1);
55 55
56 new->data = data; 56 new->data = data;
57 new->next = NULL; 57 new->next = NULL;
@@ -64,13 +64,13 @@ void sp_list_insert(sp_node_t *list, void *data) {
64 } 64 }
65} 65}
66 66
67void sp_list_prepend(sp_node_t *list, void *data) { 67void sp_list_prepend(sp_list_node *list, void *data) {
68 if (list->head == NULL) { 68 if (list->head == NULL) {
69 list->data = data; 69 list->data = data;
70 list->next = NULL; 70 list->next = NULL;
71 list->head = list; 71 list->head = list;
72 } else { 72 } else {
73 sp_node_t *new = pecalloc(sizeof(*new), 1, 1); 73 sp_list_node *new = pecalloc(sizeof(*new), 1, 1);
74 74
75 new->next = list->next; 75 new->next = list->next;
76 list->next = new; 76 list->next = new;
diff --git a/src/sp_list.h b/src/sp_list.h
index 7878f78..b6760ef 100644
--- a/src/sp_list.h
+++ b/src/sp_list.h
@@ -6,12 +6,12 @@ typedef struct sp_node_s {
6 struct sp_node_s *head; 6 struct sp_node_s *head;
7 void *data; 7 void *data;
8 8
9} sp_node_t; 9} sp_list_node;
10 10
11sp_node_t *sp_list_new(); 11sp_list_node *sp_list_new();
12sp_node_t *sp_list_sort(sp_node_t *, int (*)(sp_node_t *, sp_node_t *)); 12sp_list_node *sp_list_sort(sp_list_node *, int (*)(sp_list_node *, sp_list_node *));
13void sp_list_insert(sp_node_t *, void *); 13void sp_list_insert(sp_list_node *, void *);
14void sp_list_free(sp_node_t *); 14void sp_list_free(sp_list_node *);
15void sp_list_prepend(sp_node_t *, void *); 15void sp_list_prepend(sp_list_node *, void *);
16 16
17#endif 17#endif
diff --git a/src/sp_var_parser.c b/src/sp_var_parser.c
index b6dde03..6ec415a 100644
--- a/src/sp_var_parser.c
+++ b/src/sp_var_parser.c
@@ -1,7 +1,7 @@
1#include "php_snuffleupagus.h" 1#include "php_snuffleupagus.h"
2 2
3static int parse_str_tokens(const char *str, const sp_token_t token, 3static int parse_str_tokens(const char *str, const sp_token_t token,
4 sp_node_t *tokens_list) { 4 sp_list_node *tokens_list) {
5 const char *cur_str = str; 5 const char *cur_str = str;
6 6
7 while ((cur_str = strchr(cur_str, token.token[0]))) { 7 while ((cur_str = strchr(cur_str, token.token[0]))) {
@@ -87,7 +87,7 @@ static int create_var(sp_tree *tree, const char *restrict value,
87 return 0; 87 return 0;
88} 88}
89 89
90int cmp_tokens(sp_node_t *list1, sp_node_t *list2) { 90int cmp_tokens(sp_list_node *list1, sp_list_node *list2) {
91 return (((sp_token_t *)list1->data)->pos 91 return (((sp_token_t *)list1->data)->pos
92 - ((sp_token_t *)list2->data)->pos); 92 - ((sp_token_t *)list2->data)->pos);
93} 93}
@@ -101,7 +101,7 @@ static int is_next_token_empty(sp_token_t *token, sp_token_t *token_next,
101 return 0; 101 return 0;
102} 102}
103 103
104static int is_token_valid(sp_node_t *tokens_list, elem_type ignore, 104static int is_token_valid(sp_list_node *tokens_list, elem_type ignore,
105 int array_count, const char * restrict str, 105 int array_count, const char * restrict str,
106 size_t pos) { 106 size_t pos) {
107 sp_token_t *token = (sp_token_t *)tokens_list->data; 107 sp_token_t *token = (sp_token_t *)tokens_list->data;
@@ -157,7 +157,7 @@ static int is_token_valid(sp_node_t *tokens_list, elem_type ignore,
157} 157}
158 158
159static sp_tree *parse_tokens(const char * restrict str, 159static sp_tree *parse_tokens(const char * restrict str,
160 sp_node_t *tokens_list) { 160 sp_list_node *tokens_list) {
161 size_t pos = 0; 161 size_t pos = 0;
162 int array_count = 0, pos_idx_start = -1; 162 int array_count = 0, pos_idx_start = -1;
163 elem_type ignore = 0; 163 elem_type ignore = 0;
@@ -217,7 +217,7 @@ error:
217} 217}
218 218
219sp_tree *parse_var(const char *line) { 219sp_tree *parse_var(const char *line) {
220 sp_node_t *tokens_list = NULL; 220 sp_list_node *tokens_list = NULL;
221 sp_tree *tree = NULL; 221 sp_tree *tree = NULL;
222 const sp_token_t delimiter_list[] = { 222 const sp_token_t delimiter_list[] = {
223 {.type=OBJECT, .token=OBJECT_TOKEN}, 223 {.type=OBJECT, .token=OBJECT_TOKEN},