summaryrefslogtreecommitdiff
path: root/src/sp_utils.c
diff options
context:
space:
mode:
authorBen Fuhrmannek2021-09-23 12:23:40 +0200
committerBen Fuhrmannek2021-09-23 12:23:40 +0200
commit54c352c1b5aa08b187dd1e52e544709cad2b0fee (patch)
treed15bf0f484c6baa1f2718e625e0d49f6fb488507 /src/sp_utils.c
parent887e1c9d44fbcf5f23a928269034593b8521aaba (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_utils.c')
-rw-r--r--src/sp_utils.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/sp_utils.c b/src/sp_utils.c
index de19321..ff85494 100644
--- a/src/sp_utils.c
+++ b/src/sp_utils.c
@@ -46,7 +46,7 @@ void sp_log_msgf(char const* restrict feature, int level, int type,
46 break; 46 break;
47 } 47 }
48 48
49 switch (SNUFFLEUPAGUS_G(config).log_media) { 49 switch (SPCFG(log_media)) {
50 case SP_SYSLOG: { 50 case SP_SYSLOG: {
51 const char* error_filename = zend_get_executed_filename(); 51 const char* error_filename = zend_get_executed_filename();
52 int syslog_level = (level == E_ERROR) ? LOG_ERR : LOG_INFO; 52 int syslog_level = (level == E_ERROR) ? LOG_ERR : LOG_INFO;
@@ -244,17 +244,17 @@ const zend_string* sp_zval_to_zend_string(const zval* zv) {
244 return Z_STR_P(zv); 244 return Z_STR_P(zv);
245 } 245 }
246 case IS_FALSE: 246 case IS_FALSE:
247 return zend_string_init("FALSE", sizeof("FALSE") - 1, 0); 247 return zend_string_init(ZEND_STRL("FALSE"), 0);
248 case IS_TRUE: 248 case IS_TRUE:
249 return zend_string_init("TRUE", sizeof("TRUE") - 1, 0); 249 return zend_string_init(ZEND_STRL("TRUE"), 0);
250 case IS_NULL: 250 case IS_NULL:
251 return zend_string_init("NULL", sizeof("NULL") - 1, 0); 251 return zend_string_init(ZEND_STRL("NULL"), 0);
252 case IS_OBJECT: 252 case IS_OBJECT:
253 return zend_string_init("OBJECT", sizeof("OBJECT") - 1, 0); 253 return zend_string_init(ZEND_STRL("OBJECT"), 0);
254 case IS_ARRAY: 254 case IS_ARRAY:
255 return zend_string_init("ARRAY", sizeof("ARRAY") - 1, 0); 255 return zend_string_init(ZEND_STRL("ARRAY"), 0);
256 case IS_RESOURCE: 256 case IS_RESOURCE:
257 return zend_string_init("RESOURCE", sizeof("RESOURCE") - 1, 0); 257 return zend_string_init(ZEND_STRL("RESOURCE"), 0);
258 default: // LCOV_EXCL_LINE 258 default: // LCOV_EXCL_LINE
259 return zend_string_init("", 0, 0); // LCOV_EXCL_LINE 259 return zend_string_init("", 0, 0); // LCOV_EXCL_LINE
260 } 260 }
@@ -432,7 +432,7 @@ bool hook_function(const char* original_name, HashTable* hook_table,
432 if (NULL == mb_name) { 432 if (NULL == mb_name) {
433 return FAILURE; 433 return FAILURE;
434 } 434 }
435 memcpy(mb_name, "mb_", sizeof("mb_") - 1); 435 memcpy(mb_name, ZEND_STRL("mb_"));
436 memcpy(mb_name + 3, VAR_AND_LEN(original_name)); 436 memcpy(mb_name + 3, VAR_AND_LEN(original_name));
437 _hook_function(mb_name, hook_table, new_function); 437 _hook_function(mb_name, hook_table, new_function);
438 efree(mb_name); 438 efree(mb_name);
@@ -471,7 +471,7 @@ void unhook_functions(HashTable *ht) {
471} 471}
472 472
473bool check_is_in_eval_whitelist(const zend_string* const function_name) { 473bool check_is_in_eval_whitelist(const zend_string* const function_name) {
474 const sp_list_node* it = SNUFFLEUPAGUS_G(config).config_eval->whitelist; 474 const sp_list_node* it = SPCFG(eval).whitelist;
475 if (!it) { 475 if (!it) {
476 return false; 476 return false;
477 } 477 }