From 0d98f51e7dbde4a40c0039910d43ad378eaefa83 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Thu, 21 Dec 2017 14:03:18 +0100 Subject: 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. --- src/snuffleupagus.c | 2 +- src/sp_config.c | 4 ++-- src/sp_config.h | 16 ++++++++-------- src/sp_config_utils.c | 4 ++-- src/sp_config_utils.h | 4 ++-- src/sp_disabled_functions.c | 12 ++++++------ src/sp_execute.c | 6 +++--- src/sp_list.c | 24 ++++++++++++------------ src/sp_list.h | 12 ++++++------ src/sp_var_parser.c | 10 +++++----- 10 files changed, 47 insertions(+), 47 deletions(-) (limited to 'src') 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) { #define FREE_LST(L) \ do { \ - sp_node_t* _n = SNUFFLEUPAGUS_G(L); \ + sp_list_node* _n = SNUFFLEUPAGUS_G(L); \ sp_disabled_function_list_free(_n); \ sp_list_free(_n); \ } 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) { return SUCCESS; } -void sp_disabled_function_list_free(sp_node_t* list) { - sp_node_t* cursor = list; +void sp_disabled_function_list_free(sp_list_node* list) { + sp_list_node* cursor = list; while(cursor) { sp_disabled_function* df = cursor->data; 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 { char *function; pcre *r_function; - sp_node_t *functions_list; + sp_list_node *functions_list; char *hash; int simulation; @@ -98,8 +98,8 @@ typedef struct { char *alias; bool param_is_array; bool var_is_array; - sp_node_t *param_array_keys; - sp_node_t *var_array_keys; + sp_list_node *param_array_keys; + sp_list_node *var_array_keys; bool allow; @@ -109,7 +109,7 @@ typedef struct { } sp_disabled_function; typedef struct { - sp_node_t *disabled_functions; // list of sp_disabled_function + sp_list_node *disabled_functions; // list of sp_disabled_function } sp_config_disabled_functions; typedef struct { @@ -117,9 +117,9 @@ typedef struct { } sp_config_cookie; typedef struct { - sp_node_t *construct_include; // list of rules for `(include|require)_(once)?` - sp_node_t *construct_eval; - sp_node_t *construct_echo; + sp_list_node *construct_include; // list of rules for `(include|require)_(once)?` + sp_list_node *construct_eval; + sp_list_node *construct_echo; } sp_config_disabled_constructs; typedef struct { @@ -227,6 +227,6 @@ int parse_cidr(char *restrict, char *restrict, void *); int parse_php_type(char *restrict, char *restrict, void *); // cleanup -void sp_disabled_function_list_free(sp_node_t*); +void sp_disabled_function_list_free(sp_list_node*); #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, return NULL; } -zend_always_inline sp_node_t *parse_functions_list(char *value) { +zend_always_inline sp_list_node *parse_functions_list(char *value) { const char *sep = ">"; if (NULL == strchr(value, sep[0])) { return NULL; } - sp_node_t *list = sp_list_new(); + sp_list_node *list = sp_list_new(); char* tmp = strdup(value); char* function_name; 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 @@ int parse_keywords(sp_config_functions *, char *); char *get_param(size_t *, char *restrict, sp_type, const char *restrict); -int array_to_list(char **, sp_node_t **); -sp_node_t *parse_functions_list(char *value); +int array_to_list(char **, sp_list_node **); +sp_list_node *parse_functions_list(char *value); #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( } static bool is_functions_list_matching(zend_execute_data* execute_data, - sp_node_t* functions_list) { + sp_list_node* functions_list) { zend_execute_data *orig_execute_data, *current; orig_execute_data = current = execute_data; - sp_node_t* it = functions_list; + sp_list_node* it = functions_list; while (current) { if (it == NULL) { // every function in the list matched, we've got a match! @@ -91,7 +91,7 @@ static bool is_local_var_matching( return false; } -static const sp_node_t* get_config_node(const char* builtin_name) { +static const sp_list_node* get_config_node(const char* builtin_name) { if (!builtin_name) { return SNUFFLEUPAGUS_G(config) .config_disabled_functions->disabled_functions; @@ -214,7 +214,7 @@ static bool is_param_matching(zend_execute_data* execute_data, bool should_disable(zend_execute_data* execute_data, const char* builtin_name, const char* builtin_param, const char* builtin_param_name) { char current_file_hash[SHA256_SIZE * 2 + 1] = {0}; - const sp_node_t* config = get_config_node(builtin_name); + const sp_list_node* config = get_config_node(builtin_name); char* complete_path_function = get_complete_function_path(execute_data); char const* client_ip = getenv("REMOTE_ADDR"); const char* current_filename; @@ -341,7 +341,7 @@ allow: static bool should_drop_on_ret(zval* return_value, const zend_execute_data* const execute_data) { - const sp_node_t* config = + const sp_list_node* config = SNUFFLEUPAGUS_G(config).config_disabled_functions_ret->disabled_functions; char* complete_path_function = get_complete_function_path(execute_data); const char* current_filename = zend_get_executed_filename(TSRMLS_C); @@ -445,7 +445,7 @@ ZEND_FUNCTION(check_disabled_function) { } } -static int hook_functions(const sp_node_t* config) { +static int hook_functions(const sp_list_node* config) { while (config && config->data) { const char* function_name = ((sp_disabled_function*)config->data)->function; 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) { } static void is_builtin_matching(const char * restrict const filename, - char* restrict function_name, char* restrict param_name, sp_node_t *config) { + char* restrict function_name, char* restrict param_name, sp_list_node *config) { if (!config || !config->data) { return; } @@ -65,7 +65,7 @@ static void sp_execute_ex(zend_execute_data *execute_data) { } if (execute_data->func->op_array.type == ZEND_EVAL_CODE) { - sp_node_t* config = SNUFFLEUPAGUS_G(config).config_disabled_constructs->construct_eval; + sp_list_node* config = SNUFFLEUPAGUS_G(config).config_disabled_constructs->construct_eval; char *filename = get_eval_filename((char *)zend_get_executed_filename()); is_builtin_matching(filename, "eval", NULL, config); efree(filename); @@ -92,7 +92,7 @@ static int sp_stream_open(const char *filename, zend_file_handle *handle) { if (true == SNUFFLEUPAGUS_G(config).config_readonly_exec->enable) { terminate_if_writable(filename); } - sp_node_t* config = SNUFFLEUPAGUS_G(config).config_disabled_constructs->construct_include; + sp_list_node* config = SNUFFLEUPAGUS_G(config).config_disabled_constructs->construct_include; switch (data->opline->extended_value) { case ZEND_INCLUDE: 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 @@ #include #include "php_snuffleupagus.h" -void sp_list_free(sp_node_t *node) { +void sp_list_free(sp_list_node *node) { while(node) { - sp_node_t *tmp = node->next; + sp_list_node *tmp = node->next; pefree(node, 1); node = tmp; } } -sp_node_t *sp_list_new() { - sp_node_t *new = pecalloc(sizeof(*new), 1, 1); +sp_list_node *sp_list_new() { + sp_list_node *new = pecalloc(sizeof(*new), 1, 1); new->next = new->data = new->head = NULL; return new; } // Thanks to https://en.wikipedia.org/wiki/Insertion_sort :> -sp_node_t *sp_list_sort(sp_node_t *pList, int (*cmp_func)(sp_node_t *, sp_node_t *)) { - sp_node_t *head = NULL; +sp_list_node *sp_list_sort(sp_list_node *pList, int (*cmp_func)(sp_list_node *, sp_list_node *)) { + sp_list_node *head = NULL; if (pList == NULL || pList->next == NULL) { return pList; } while (pList != NULL) { - sp_node_t *current = pList; + sp_list_node *current = pList; pList = pList->next; if (head == NULL || 0 > cmp_func(current, head)) { current->next = head; head = current; } else { - sp_node_t *p = head; + sp_list_node *p = head; while (p != NULL) { if (p->next == NULL || 0 > cmp_func(current, p->next)) { 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 return head; } -void sp_list_insert(sp_node_t *list, void *data) { +void sp_list_insert(sp_list_node *list, void *data) { if (list->head == NULL) { list->data = data; list->next = NULL; list->head = list; } else { - sp_node_t *new = pecalloc(sizeof(*new), 1, 1); + sp_list_node *new = pecalloc(sizeof(*new), 1, 1); new->data = data; new->next = NULL; @@ -64,13 +64,13 @@ void sp_list_insert(sp_node_t *list, void *data) { } } -void sp_list_prepend(sp_node_t *list, void *data) { +void sp_list_prepend(sp_list_node *list, void *data) { if (list->head == NULL) { list->data = data; list->next = NULL; list->head = list; } else { - sp_node_t *new = pecalloc(sizeof(*new), 1, 1); + sp_list_node *new = pecalloc(sizeof(*new), 1, 1); new->next = list->next; 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 { struct sp_node_s *head; void *data; -} sp_node_t; +} sp_list_node; -sp_node_t *sp_list_new(); -sp_node_t *sp_list_sort(sp_node_t *, int (*)(sp_node_t *, sp_node_t *)); -void sp_list_insert(sp_node_t *, void *); -void sp_list_free(sp_node_t *); -void sp_list_prepend(sp_node_t *, void *); +sp_list_node *sp_list_new(); +sp_list_node *sp_list_sort(sp_list_node *, int (*)(sp_list_node *, sp_list_node *)); +void sp_list_insert(sp_list_node *, void *); +void sp_list_free(sp_list_node *); +void sp_list_prepend(sp_list_node *, void *); #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 @@ #include "php_snuffleupagus.h" static int parse_str_tokens(const char *str, const sp_token_t token, - sp_node_t *tokens_list) { + sp_list_node *tokens_list) { const char *cur_str = str; while ((cur_str = strchr(cur_str, token.token[0]))) { @@ -87,7 +87,7 @@ static int create_var(sp_tree *tree, const char *restrict value, return 0; } -int cmp_tokens(sp_node_t *list1, sp_node_t *list2) { +int cmp_tokens(sp_list_node *list1, sp_list_node *list2) { return (((sp_token_t *)list1->data)->pos - ((sp_token_t *)list2->data)->pos); } @@ -101,7 +101,7 @@ static int is_next_token_empty(sp_token_t *token, sp_token_t *token_next, return 0; } -static int is_token_valid(sp_node_t *tokens_list, elem_type ignore, +static int is_token_valid(sp_list_node *tokens_list, elem_type ignore, int array_count, const char * restrict str, size_t pos) { 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, } static sp_tree *parse_tokens(const char * restrict str, - sp_node_t *tokens_list) { + sp_list_node *tokens_list) { size_t pos = 0; int array_count = 0, pos_idx_start = -1; elem_type ignore = 0; @@ -217,7 +217,7 @@ error: } sp_tree *parse_var(const char *line) { - sp_node_t *tokens_list = NULL; + sp_list_node *tokens_list = NULL; sp_tree *tree = NULL; const sp_token_t delimiter_list[] = { {.type=OBJECT, .token=OBJECT_TOKEN}, -- cgit v1.3