summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjvoisin2017-10-12 23:58:34 +0200
committerjvoisin2017-10-12 23:59:51 +0200
commitaf7d8bb0d41f81709db920efaacf48d69294f2a7 (patch)
treee64c2dbc0e8d0a74dc139b83c9d4e7976efc5240 /src
parent428c1098031fefb0ef73e3b8be8cecad148a6ab5 (diff)
Minor refactoring
- use the `is_regexp_matching` function when possible - check parameters before passing it to `pcre_exec` - improve error messages wrt. regexp
Diffstat (limited to 'src')
-rw-r--r--src/sp_utils.c61
1 files changed, 31 insertions, 30 deletions
diff --git a/src/sp_utils.c b/src/sp_utils.c
index 281b432..e0c36d0 100644
--- a/src/sp_utils.c
+++ b/src/sp_utils.c
@@ -29,6 +29,36 @@ void sp_log_msg(char const *feature, char const *level, const char* fmt, ...) {
29 feature, level, msg); 29 feature, level, msg);
30} 30}
31 31
32
33zend_always_inline char* sp_getenv(char* var) {
34 if (sapi_module.getenv) {
35 return sapi_module.getenv(ZEND_STRL(var));
36 } else {
37 return getenv(var);
38 }
39}
40
41zend_always_inline int is_regexp_matching(const pcre* regexp, const char* str) {
42 int vec[30];
43 int ret = 0;
44
45 if (!regexp || !str) {
46 sp_log_err("regexp", "Something went wrong with a regexp (%d:%d).",
47 !regexp?0:1, !str?0:1);
48 return false;
49 }
50
51 ret = sp_pcre_exec(regexp, NULL, str, strlen(str), 0, 0, vec, sizeof(vec));
52
53 if (ret < 0) {
54 if (ret != PCRE_ERROR_NOMATCH) {
55 sp_log_err("regexp", "Something went wrong with a regexp (%d).", ret);
56 }
57 return false;
58 }
59 return true;
60}
61
32int compute_hash(const char* const filename, char* file_hash) { 62int compute_hash(const char* const filename, char* file_hash) {
33 unsigned char buf[1024]; 63 unsigned char buf[1024];
34 unsigned char digest[SHA256_SIZE]; 64 unsigned char digest[SHA256_SIZE];
@@ -208,17 +238,7 @@ bool sp_match_value(const char* value, const char* to_match, const pcre* rx) {
208 return true; 238 return true;
209 } 239 }
210 } else if (rx) { 240 } else if (rx) {
211 int substrvec[30]; 241 return is_regexp_matching(rx, value);
212 int ret = sp_pcre_exec(rx, NULL, value, strlen(value), 0, 0, substrvec, 30);
213
214 if (ret < 0) {
215 if (ret != PCRE_ERROR_NOMATCH) {
216 sp_log_err("regexp", "Something went wrong with a regexp (%d).", ret);
217 return false;
218 }
219 return false;
220 }
221 return true;
222 } 242 }
223 return false; 243 return false;
224} 244}
@@ -347,25 +367,6 @@ int sp_match_array_key_recurse(const zval* arr, sp_node_t* keys,
347 return 0; 367 return 0;
348} 368}
349 369
350zend_always_inline char* sp_getenv(char* var) {
351 if (sapi_module.getenv) {
352 return sapi_module.getenv(ZEND_STRL(var));
353 } else {
354 return getenv(var);
355 }
356}
357
358zend_always_inline int is_regexp_matching(const pcre* regexp, const char* str) {
359 int vec[30];
360 int ret = sp_pcre_exec(regexp, NULL, str, strlen(str), 0, 0, vec, sizeof(vec));
361 if (ret < 0) {
362 if (ret != PCRE_ERROR_NOMATCH) {
363 sp_log_err("regexp", "Something went wrong with a regexp (%d).", ret);
364 }
365 return false;
366 }
367 return true;
368}
369 370
370int hook_function(const char* original_name, HashTable* hook_table, 371int hook_function(const char* original_name, HashTable* hook_table,
371 void (*new_function)(INTERNAL_FUNCTION_PARAMETERS), 372 void (*new_function)(INTERNAL_FUNCTION_PARAMETERS),