summaryrefslogtreecommitdiff
path: root/src/sp_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sp_utils.c')
-rw-r--r--src/sp_utils.c33
1 files changed, 6 insertions, 27 deletions
diff --git a/src/sp_utils.c b/src/sp_utils.c
index 0625a2f..2979d98 100644
--- a/src/sp_utils.c
+++ b/src/sp_utils.c
@@ -32,25 +32,6 @@ void sp_log_msg(char const* feature, char const* level, const char* fmt, ...) {
32 client_ip ? client_ip : "0.0.0.0", feature, level, msg); 32 client_ip ? client_ip : "0.0.0.0", feature, level, msg);
33} 33}
34 34
35zend_always_inline int is_regexp_matching(const pcre* regexp, const char* str) {
36 int vec[30];
37 int ret = 0;
38
39 assert(NULL != regexp);
40 assert(NULL != str);
41
42 ret = sp_pcre_exec(regexp, NULL, str, strlen(str), 0, 0, vec,
43 sizeof(vec) / sizeof(int));
44
45 if (ret < 0) {
46 if (ret != PCRE_ERROR_NOMATCH) {
47 sp_log_err("regexp", "Something went wrong with a regexp (%d).", ret);
48 }
49 return false;
50 }
51 return true;
52}
53
54int compute_hash(const char* const filename, char* file_hash) { 35int compute_hash(const char* const filename, char* file_hash) {
55 unsigned char buf[1024]; 36 unsigned char buf[1024];
56 unsigned char digest[SHA256_SIZE]; 37 unsigned char digest[SHA256_SIZE];
@@ -192,13 +173,13 @@ char* sp_convert_to_string(zval* zv) {
192 return estrdup(""); 173 return estrdup("");
193} 174}
194 175
195bool sp_match_value(const char* value, const char* to_match, const pcre* rx) { 176bool sp_match_value(const char* value, const char* to_match, const sp_pcre* rx) {
196 if (to_match) { 177 if (to_match) {
197 if (0 == strcmp(to_match, value)) { 178 if (0 == strcmp(to_match, value)) {
198 return true; 179 return true;
199 } 180 }
200 } else if (rx) { 181 } else if (rx) {
201 return is_regexp_matching(rx, value); 182 return sp_is_regexp_matching(rx, value);
202 } else { 183 } else {
203 return true; 184 return true;
204 } 185 }
@@ -274,7 +255,7 @@ void sp_log_disable_ret(const char* restrict path,
274 } 255 }
275} 256}
276 257
277bool sp_match_array_key(const zval* zv, const char* to_match, const pcre* rx) { 258bool sp_match_array_key(const zval* zv, const char* to_match, const sp_pcre* rx) {
278 zend_string* key; 259 zend_string* key;
279 zend_ulong idx; 260 zend_ulong idx;
280 261
@@ -298,7 +279,7 @@ bool sp_match_array_key(const zval* zv, const char* to_match, const pcre* rx) {
298} 279}
299 280
300bool sp_match_array_value(const zval* arr, const char* to_match, 281bool sp_match_array_value(const zval* arr, const char* to_match,
301 const pcre* rx) { 282 const sp_pcre* rx) {
302 zval* value; 283 zval* value;
303 284
304 ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(arr), value) { 285 ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(arr), value) {
@@ -368,7 +349,7 @@ int hook_function(const char* original_name, HashTable* hook_table,
368 return SUCCESS; 349 return SUCCESS;
369} 350}
370 351
371int hook_regexp(const pcre* regexp, HashTable* hook_table, 352int hook_regexp(const sp_pcre* regexp, HashTable* hook_table,
372 void (*new_function)(INTERNAL_FUNCTION_PARAMETERS), 353 void (*new_function)(INTERNAL_FUNCTION_PARAMETERS),
373 bool hook_execution_table) { 354 bool hook_execution_table) {
374 zend_string* key; 355 zend_string* key;
@@ -377,9 +358,7 @@ int hook_regexp(const pcre* regexp, HashTable* hook_table,
377 358
378 ZEND_HASH_FOREACH_STR_KEY(ht, key) { 359 ZEND_HASH_FOREACH_STR_KEY(ht, key) {
379 if (key) { 360 if (key) {
380 int vec[30]; 361 int ret = sp_is_regexp_matching_len(regexp, key->val, key->len);
381 int ret = sp_pcre_exec(regexp, NULL, key->val, key->len, 0, 0, vec,
382 sizeof(vec) / sizeof(int));
383 if (ret < 0) { /* Error or no match*/ 362 if (ret < 0) { /* Error or no match*/
384 if (PCRE_ERROR_NOMATCH != ret) { 363 if (PCRE_ERROR_NOMATCH != ret) {
385 sp_log_err("pcre", "Runtime error with pcre, error code: %d", ret); 364 sp_log_err("pcre", "Runtime error with pcre, error code: %d", ret);