diff options
| author | Ben Fuhrmannek | 2021-09-23 12:23:40 +0200 |
|---|---|---|
| committer | Ben Fuhrmannek | 2021-09-23 12:23:40 +0200 |
| commit | 54c352c1b5aa08b187dd1e52e544709cad2b0fee (patch) | |
| tree | d15bf0f484c6baa1f2718e625e0d49f6fb488507 /src/sp_config_keywords.c | |
| parent | 887e1c9d44fbcf5f23a928269034593b8521aaba (diff) | |
config is stack allocated now + some code improvements (see details)
* for easier memory manegement, the entire sp_config struct was merged into snuffleupagus_globals and allocated on stack where possible
* SNUFFLEUPAGUS_G() can be written as SPG(), which is faster to type and easier to read
* execution_depth is re-initialized to 0 for each request
* function calls with inline string and length parameters consistently use ZEND_STRL instead of sizeof()-1
* execution is actually hooked if recursion protection is enabled
* some line breaks were removed to make the code more readable
Diffstat (limited to 'src/sp_config_keywords.c')
| -rw-r--r-- | src/sp_config_keywords.c | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index bd8a9a1..f6af86b 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c | |||
| @@ -49,12 +49,12 @@ SP_PARSE_FN(parse_session) { | |||
| 49 | #endif | 49 | #endif |
| 50 | 50 | ||
| 51 | if (cfg->encrypt) { | 51 | if (cfg->encrypt) { |
| 52 | if (!SNUFFLEUPAGUS_G(config).config_snuffleupagus->cookies_env_var) { | 52 | if (!SPCFG(cookies_env_var)) { |
| 53 | sp_log_err("config", "You're trying to use the session cookie encryption feature " | 53 | sp_log_err("config", "You're trying to use the session cookie encryption feature " |
| 54 | "on line %zu without having set the `.cookie_env_var` option in " | 54 | "on line %zu without having set the `.cookie_env_var` option in " |
| 55 | "`sp.global`: please set it first", parsed_rule->lineno); | 55 | "`sp.global`: please set it first", parsed_rule->lineno); |
| 56 | return SP_PARSER_ERROR; | 56 | return SP_PARSER_ERROR; |
| 57 | } else if (!SNUFFLEUPAGUS_G(config).config_snuffleupagus->encryption_key) { | 57 | } else if (!SPCFG(encryption_key)) { |
| 58 | sp_log_err("config", "You're trying to use the session cookie encryption feature " | 58 | sp_log_err("config", "You're trying to use the session cookie encryption feature " |
| 59 | "on line %zu without having set the `.secret_key` option in " | 59 | "on line %zu without having set the `.secret_key` option in " |
| 60 | "`sp.global`: please set it first", parsed_rule->lineno); | 60 | "`sp.global`: please set it first", parsed_rule->lineno); |
| @@ -127,12 +127,12 @@ SP_PARSE_FN(parse_readonly_exec) { | |||
| 127 | 127 | ||
| 128 | SP_PARSE_FN(parse_global) { | 128 | SP_PARSE_FN(parse_global) { |
| 129 | sp_config_keyword config_keywords[] = { | 129 | sp_config_keyword config_keywords[] = { |
| 130 | {parse_str, SP_TOKEN_ENCRYPTION_KEY, &(SNUFFLEUPAGUS_G(config).config_snuffleupagus->encryption_key)}, | 130 | {parse_str, SP_TOKEN_ENCRYPTION_KEY, &(SPCFG(encryption_key))}, |
| 131 | {parse_str, SP_TOKEN_ENV_VAR, &(SNUFFLEUPAGUS_G(config).config_snuffleupagus->cookies_env_var)}, | 131 | {parse_str, SP_TOKEN_ENV_VAR, &(SPCFG(cookies_env_var))}, |
| 132 | {parse_log_media, SP_TOKEN_LOG_MEDIA, &(SNUFFLEUPAGUS_G(config).log_media)}, | 132 | {parse_log_media, SP_TOKEN_LOG_MEDIA, &(SPCFG(log_media))}, |
| 133 | {parse_ulong, SP_TOKEN_MAX_EXECUTION_DEPTH, &(SNUFFLEUPAGUS_G(config).max_execution_depth)}, | 133 | {parse_ulong, SP_TOKEN_MAX_EXECUTION_DEPTH, &(SPCFG(max_execution_depth))}, |
| 134 | {parse_enable, SP_TOKEN_SERVER_ENCODE, &(SNUFFLEUPAGUS_G(config).server_encode)}, | 134 | {parse_enable, SP_TOKEN_SERVER_ENCODE, &(SPCFG(server_encode))}, |
| 135 | {parse_enable, SP_TOKEN_SERVER_STRIP, &(SNUFFLEUPAGUS_G(config).server_strip)}, | 135 | {parse_enable, SP_TOKEN_SERVER_STRIP, &(SPCFG(server_strip))}, |
| 136 | {0, 0, 0}}; | 136 | {0, 0, 0}}; |
| 137 | 137 | ||
| 138 | SP_PROCESS_CONFIG_KEYWORDS_ERR(); | 138 | SP_PROCESS_CONFIG_KEYWORDS_ERR(); |
| @@ -140,7 +140,7 @@ SP_PARSE_FN(parse_global) { | |||
| 140 | } | 140 | } |
| 141 | 141 | ||
| 142 | SP_PARSE_FN(parse_eval_filter_conf) { | 142 | SP_PARSE_FN(parse_eval_filter_conf) { |
| 143 | sp_config_eval *cfg = SNUFFLEUPAGUS_G(config).config_eval; | 143 | sp_config_eval *cfg = &(SPCFG(eval)); |
| 144 | 144 | ||
| 145 | sp_config_keyword config_keywords[] = { | 145 | sp_config_keyword config_keywords[] = { |
| 146 | {parse_list, SP_TOKEN_LIST, retval}, | 146 | {parse_list, SP_TOKEN_LIST, retval}, |
| @@ -186,11 +186,11 @@ SP_PARSE_FN(parse_cookie) { | |||
| 186 | SP_PROCESS_CONFIG_KEYWORDS(goto err); | 186 | SP_PROCESS_CONFIG_KEYWORDS(goto err); |
| 187 | 187 | ||
| 188 | if (cookie->encrypt) { | 188 | if (cookie->encrypt) { |
| 189 | if (!SNUFFLEUPAGUS_G(config).config_snuffleupagus->cookies_env_var) { | 189 | if (!SPCFG(cookies_env_var)) { |
| 190 | sp_log_err("config", "You're trying to use the cookie encryption feature on line %zu " | 190 | sp_log_err("config", "You're trying to use the cookie encryption feature on line %zu " |
| 191 | "without having set the `." SP_TOKEN_ENV_VAR "` option in `sp.global`: please set it first", parsed_rule->lineno); | 191 | "without having set the `." SP_TOKEN_ENV_VAR "` option in `sp.global`: please set it first", parsed_rule->lineno); |
| 192 | goto err; | 192 | goto err; |
| 193 | } else if (!SNUFFLEUPAGUS_G(config).config_snuffleupagus->encryption_key) { | 193 | } else if (!SPCFG(encryption_key)) { |
| 194 | sp_log_err("config", "You're trying to use the cookie encryption feature " | 194 | sp_log_err("config", "You're trying to use the cookie encryption feature " |
| 195 | "on line %zu without having set the `." SP_TOKEN_ENCRYPTION_KEY "` option in " | 195 | "on line %zu without having set the `." SP_TOKEN_ENCRYPTION_KEY "` option in " |
| 196 | "`sp." SP_TOKEN_GLOBAL "`: please set it first", parsed_rule->lineno); | 196 | "`sp." SP_TOKEN_GLOBAL "`: please set it first", parsed_rule->lineno); |
| @@ -220,7 +220,7 @@ SP_PARSE_FN(parse_cookie) { | |||
| 220 | } | 220 | } |
| 221 | } | 221 | } |
| 222 | 222 | ||
| 223 | SNUFFLEUPAGUS_G(config).config_cookie->cookies = sp_list_insert(SNUFFLEUPAGUS_G(config).config_cookie->cookies, cookie); | 223 | SPCFG(cookie).cookies = sp_list_insert(SPCFG(cookie).cookies, cookie); |
| 224 | 224 | ||
| 225 | return SP_PARSER_STOP; | 225 | return SP_PARSER_STOP; |
| 226 | 226 | ||
| @@ -316,7 +316,7 @@ SP_PARSE_FN(parse_disabled_functions) { | |||
| 316 | goto out; | 316 | goto out; |
| 317 | } | 317 | } |
| 318 | if (df->filename && (*ZSTR_VAL(df->filename) != '/') && | 318 | if (df->filename && (*ZSTR_VAL(df->filename) != '/') && |
| 319 | (0 != strncmp(ZSTR_VAL(df->filename), "phar://", strlen("phar://")))) { | 319 | (0 != strncmp(ZSTR_VAL(df->filename), ZEND_STRL("phar://")))) { |
| 320 | sp_log_err("config", "Invalid configuration line: 'sp.disabled_functions': '.filename' must be an absolute path or a phar archive on line %zu", parsed_rule->lineno); | 320 | sp_log_err("config", "Invalid configuration line: 'sp.disabled_functions': '.filename' must be an absolute path or a phar archive on line %zu", parsed_rule->lineno); |
| 321 | goto out; | 321 | goto out; |
| 322 | } | 322 | } |
| @@ -365,20 +365,20 @@ SP_PARSE_FN(parse_disabled_functions) { | |||
| 365 | 365 | ||
| 366 | if (df->function && zend_string_equals_literal(df->function, "print")) { | 366 | if (df->function && zend_string_equals_literal(df->function, "print")) { |
| 367 | zend_string_release(df->function); | 367 | zend_string_release(df->function); |
| 368 | df->function = zend_string_init("echo", sizeof("echo") - 1, 1); | 368 | df->function = zend_string_init(ZEND_STRL("echo"), 1); |
| 369 | } | 369 | } |
| 370 | 370 | ||
| 371 | if (df->function && !df->functions_list) { | 371 | if (df->function && !df->functions_list) { |
| 372 | if (df->ret || df->r_ret || df->ret_type) { | 372 | if (df->ret || df->r_ret || df->ret_type) { |
| 373 | add_df_to_hashtable(SNUFFLEUPAGUS_G(config).config_disabled_functions_ret, df); | 373 | add_df_to_hashtable(SPCFG(disabled_functions_ret), df); |
| 374 | } else { | 374 | } else { |
| 375 | add_df_to_hashtable(SNUFFLEUPAGUS_G(config).config_disabled_functions, df); | 375 | add_df_to_hashtable(SPCFG(disabled_functions), df); |
| 376 | } | 376 | } |
| 377 | } else { | 377 | } else { |
| 378 | if (df->ret || df->r_ret || df->ret_type) { | 378 | if (df->ret || df->r_ret || df->ret_type) { |
| 379 | SNUFFLEUPAGUS_G(config).config_disabled_functions_reg_ret->disabled_functions = sp_list_insert(SNUFFLEUPAGUS_G(config).config_disabled_functions_reg_ret->disabled_functions, df); | 379 | SPCFG(disabled_functions_reg_ret).disabled_functions = sp_list_insert(SPCFG(disabled_functions_reg_ret).disabled_functions, df); |
| 380 | } else { | 380 | } else { |
| 381 | SNUFFLEUPAGUS_G(config).config_disabled_functions_reg->disabled_functions = sp_list_insert(SNUFFLEUPAGUS_G(config).config_disabled_functions_reg->disabled_functions, df); | 381 | SPCFG(disabled_functions_reg).disabled_functions = sp_list_insert(SPCFG(disabled_functions_reg).disabled_functions, df); |
| 382 | } | 382 | } |
| 383 | } | 383 | } |
| 384 | return SP_PARSER_STOP; | 384 | return SP_PARSER_STOP; |
| @@ -493,7 +493,7 @@ SP_PARSE_FN(parse_ini_entry) { | |||
| 493 | } | 493 | } |
| 494 | entry->access = ro - rw; | 494 | entry->access = ro - rw; |
| 495 | 495 | ||
| 496 | zend_hash_add_ptr(SNUFFLEUPAGUS_G(config).config_ini->entries, entry->key, entry); | 496 | zend_hash_add_ptr(SPCFG(ini).entries, entry->key, entry); |
| 497 | return SP_PARSER_STOP; | 497 | return SP_PARSER_STOP; |
| 498 | 498 | ||
| 499 | err: | 499 | err: |
