diff options
| author | jvoisin | 2022-07-12 21:54:19 +0200 |
|---|---|---|
| committer | jvoisin | 2022-07-12 21:54:19 +0200 |
| commit | 8795ce1a92d226e31668db2f6cfbd33b40632109 (patch) | |
| tree | 4fa2b33f574de1ca3d6345f43f3df37df35715ce /src | |
| parent | 83014d7df165f8b8a9bf6dd4fde93fd1d42e4b7e (diff) | |
Constify some variables
Diffstat (limited to 'src')
| -rw-r--r-- | src/snuffleupagus.c | 13 | ||||
| -rw-r--r-- | src/sp_ini.c | 11 |
2 files changed, 13 insertions, 11 deletions
diff --git a/src/snuffleupagus.c b/src/snuffleupagus.c index 4c9e904..5bcd57c 100644 --- a/src/snuffleupagus.c +++ b/src/snuffleupagus.c | |||
| @@ -254,7 +254,7 @@ PHP_MINFO_FUNCTION(snuffleupagus) { | |||
| 254 | #define ADD_ASSOC_ZSTR(arr, key, zstr) if (zstr) { add_assoc_str(arr, key, zstr); } else { add_assoc_null(arr, key); } | 254 | #define ADD_ASSOC_ZSTR(arr, key, zstr) if (zstr) { add_assoc_str(arr, key, zstr); } else { add_assoc_null(arr, key); } |
| 255 | #define ADD_ASSOC_REGEXP(arr, key, regexp) if (regexp && regexp->pattern) { add_assoc_str(arr, key, regexp->pattern); } else { add_assoc_null(arr, key); } | 255 | #define ADD_ASSOC_REGEXP(arr, key, regexp) if (regexp && regexp->pattern) { add_assoc_str(arr, key, regexp->pattern); } else { add_assoc_null(arr, key); } |
| 256 | 256 | ||
| 257 | static void add_df_to_arr(zval *arr, sp_disabled_function *df) { | 257 | static void add_df_to_arr(zval *arr, sp_disabled_function const *const df) { |
| 258 | zval arr_df; | 258 | zval arr_df; |
| 259 | array_init(&arr_df); | 259 | array_init(&arr_df); |
| 260 | 260 | ||
| @@ -365,7 +365,7 @@ static void dump_config() { | |||
| 365 | if (splist) { \ | 365 | if (splist) { \ |
| 366 | zval arr_sp; \ | 366 | zval arr_sp; \ |
| 367 | array_init(&arr_sp); \ | 367 | array_init(&arr_sp); \ |
| 368 | for (sp_list_node *p = splist; p; p = p->next) { add_next_index_str(&arr_sp, p->data); } \ | 368 | for (const sp_list_node *p = splist; p; p = p->next) { add_next_index_str(&arr_sp, p->data); } \ |
| 369 | add_assoc_zval(arr, key, &arr_sp); \ | 369 | add_assoc_zval(arr, key, &arr_sp); \ |
| 370 | } else { add_assoc_null(arr, key); } | 370 | } else { add_assoc_null(arr, key); } |
| 371 | 371 | ||
| @@ -381,6 +381,8 @@ static void dump_config() { | |||
| 381 | 381 | ||
| 382 | ADD_ASSOC_SPLIST(&arr, SP_TOKEN_ALLOW_WRAPPERS, SPCFG(wrapper).whitelist); | 382 | ADD_ASSOC_SPLIST(&arr, SP_TOKEN_ALLOW_WRAPPERS, SPCFG(wrapper).whitelist); |
| 383 | 383 | ||
| 384 | #undef ADD_ASSOC_SPLIST | ||
| 385 | |||
| 384 | add_assoc_bool(&arr, SP_TOKEN_INI_PROTECTION "." SP_TOKEN_ENABLE, SPCFG(ini).enable); | 386 | add_assoc_bool(&arr, SP_TOKEN_INI_PROTECTION "." SP_TOKEN_ENABLE, SPCFG(ini).enable); |
| 385 | add_assoc_bool(&arr, SP_TOKEN_INI_PROTECTION "." SP_TOKEN_SIM, SPCFG(ini).simulation); | 387 | add_assoc_bool(&arr, SP_TOKEN_INI_PROTECTION "." SP_TOKEN_SIM, SPCFG(ini).simulation); |
| 386 | add_assoc_bool(&arr, SP_TOKEN_INI_PROTECTION "." "policy_ro", SPCFG(ini).policy_readonly); | 388 | add_assoc_bool(&arr, SP_TOKEN_INI_PROTECTION "." "policy_ro", SPCFG(ini).policy_readonly); |
| @@ -392,7 +394,7 @@ static void dump_config() { | |||
| 392 | zval arr_ini; | 394 | zval arr_ini; |
| 393 | array_init(&arr_ini); | 395 | array_init(&arr_ini); |
| 394 | 396 | ||
| 395 | sp_ini_entry *sp_entry; | 397 | const sp_ini_entry *sp_entry; |
| 396 | ZEND_HASH_FOREACH_PTR(SPCFG(ini).entries, sp_entry) | 398 | ZEND_HASH_FOREACH_PTR(SPCFG(ini).entries, sp_entry) |
| 397 | zval arr_ini_entry; | 399 | zval arr_ini_entry; |
| 398 | array_init(&arr_ini_entry); | 400 | array_init(&arr_ini_entry); |
| @@ -442,7 +444,8 @@ static void dump_config() { | |||
| 442 | zval arr_dfs; | 444 | zval arr_dfs; |
| 443 | array_init(&arr_dfs); | 445 | array_init(&arr_dfs); |
| 444 | size_t num_df = 0; | 446 | size_t num_df = 0; |
| 445 | sp_list_node *dflist, *dfp; | 447 | const sp_list_node *dflist; |
| 448 | const sp_list_node *dfp; | ||
| 446 | ZEND_HASH_FOREACH_PTR(SPCFG(disabled_functions), dflist) | 449 | ZEND_HASH_FOREACH_PTR(SPCFG(disabled_functions), dflist) |
| 447 | for (dfp = dflist; dfp; dfp = dfp->next) { | 450 | for (dfp = dflist; dfp; dfp = dfp->next) { |
| 448 | add_df_to_arr(&arr_dfs, dfp->data); | 451 | add_df_to_arr(&arr_dfs, dfp->data); |
| @@ -597,7 +600,7 @@ static PHP_INI_MH(OnUpdateConfiguration) { | |||
| 597 | (SPCFG(disabled_functions_ret) && zend_hash_num_elements(SPCFG(disabled_functions_ret))); | 600 | (SPCFG(disabled_functions_ret) && zend_hash_num_elements(SPCFG(disabled_functions_ret))); |
| 598 | 601 | ||
| 599 | if (SPCFG(show_old_php_warning) && getenv("SP_SKIP_OLD_PHP_CHECK") == NULL) { | 602 | if (SPCFG(show_old_php_warning) && getenv("SP_SKIP_OLD_PHP_CHECK") == NULL) { |
| 600 | time_t ts = time(NULL); | 603 | const time_t ts = time(NULL); |
| 601 | if ((PHP_VERSION_ID < 70300) || | 604 | if ((PHP_VERSION_ID < 70300) || |
| 602 | (PHP_VERSION_ID < 70400 && ts >= (time_t)1638745200L) || | 605 | (PHP_VERSION_ID < 70400 && ts >= (time_t)1638745200L) || |
| 603 | (PHP_VERSION_ID < 80000 && ts >= (time_t)1669590000L) || | 606 | (PHP_VERSION_ID < 80000 && ts >= (time_t)1669590000L) || |
diff --git a/src/sp_ini.c b/src/sp_ini.c index 7fec297..ed23fb7 100644 --- a/src/sp_ini.c +++ b/src/sp_ini.c | |||
| @@ -12,12 +12,12 @@ | |||
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | static bool /* success */ sp_ini_check(zend_string *varname, zend_string *new_value, sp_ini_entry **sp_entry_p) { | 15 | static bool /* success */ sp_ini_check(zend_string *const restrict varname, zend_string const *const restrict new_value, sp_ini_entry **sp_entry_p) { |
| 16 | if (!varname || ZSTR_LEN(varname) == 0) { | 16 | if (!varname || ZSTR_LEN(varname) == 0) { |
| 17 | return false; | 17 | return false; |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | sp_config_ini *cfg = &(SPCFG(ini)); | 20 | sp_config_ini const* const cfg = &(SPCFG(ini)); |
| 21 | sp_ini_entry *entry = zend_hash_find_ptr(cfg->entries, varname); | 21 | sp_ini_entry *entry = zend_hash_find_ptr(cfg->entries, varname); |
| 22 | if (sp_entry_p) { | 22 | if (sp_entry_p) { |
| 23 | *sp_entry_p = entry; | 23 | *sp_entry_p = entry; |
| @@ -76,10 +76,9 @@ static bool /* success */ sp_ini_check(zend_string *varname, zend_string *new_va | |||
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | static PHP_INI_MH(sp_ini_onmodify) { | 78 | static PHP_INI_MH(sp_ini_onmodify) { |
| 79 | zend_ini_entry *ini_entry = entry; | ||
| 80 | sp_ini_entry *sp_entry = NULL; | 79 | sp_ini_entry *sp_entry = NULL; |
| 81 | 80 | ||
| 82 | if (!sp_ini_check(ini_entry->name, new_value, &sp_entry)) { | 81 | if (!sp_ini_check(entry->name, new_value, &sp_entry)) { |
| 83 | return FAILURE; | 82 | return FAILURE; |
| 84 | } | 83 | } |
| 85 | 84 | ||
| @@ -91,7 +90,7 @@ static PHP_INI_MH(sp_ini_onmodify) { | |||
| 91 | } | 90 | } |
| 92 | 91 | ||
| 93 | void sp_hook_ini() { | 92 | void sp_hook_ini() { |
| 94 | sp_config_ini *cfg = &(SPCFG(ini)); | 93 | sp_config_ini const* const cfg = &(SPCFG(ini)); |
| 95 | sp_ini_entry *sp_entry; | 94 | sp_ini_entry *sp_entry; |
| 96 | zend_ini_entry *ini_entry; | 95 | zend_ini_entry *ini_entry; |
| 97 | ZEND_HASH_FOREACH_PTR(cfg->entries, sp_entry) | 96 | ZEND_HASH_FOREACH_PTR(cfg->entries, sp_entry) |
| @@ -126,8 +125,8 @@ void sp_hook_ini() { | |||
| 126 | 125 | ||
| 127 | void sp_unhook_ini() { | 126 | void sp_unhook_ini() { |
| 128 | sp_ini_entry *sp_entry; | 127 | sp_ini_entry *sp_entry; |
| 129 | zend_ini_entry *ini_entry; | ||
| 130 | ZEND_HASH_FOREACH_PTR(SPCFG(ini).entries, sp_entry) | 128 | ZEND_HASH_FOREACH_PTR(SPCFG(ini).entries, sp_entry) |
| 129 | zend_ini_entry *ini_entry; | ||
| 131 | if (!sp_entry->orig_onmodify) { | 130 | if (!sp_entry->orig_onmodify) { |
| 132 | // not hooked or no original onmodify | 131 | // not hooked or no original onmodify |
| 133 | continue; | 132 | continue; |
