|
21 | 21 | #include "ngx_http_modsecurity_common.h"
|
22 | 22 |
|
23 | 23 |
|
24 |
| -// FIXME: This function should be replaced, it is being used just for test. |
25 |
| -char * |
26 |
| -str_replace ( const char *string, const char *substr, const char *replacement ){ |
27 |
| - char *tok = NULL; |
28 |
| - char *newstr = NULL; |
29 |
| - char *oldstr = NULL; |
30 |
| - char *head = NULL; |
31 |
| - |
32 |
| - /* if either substr or replacement is NULL, duplicate string a let caller handle it */ |
33 |
| - if ( substr == NULL || replacement == NULL ) return strdup (string); |
34 |
| - newstr = strdup (string); |
35 |
| - head = newstr; |
36 |
| - while ( (tok = strstr ( head, substr ))){ |
37 |
| - oldstr = newstr; |
38 |
| - newstr = malloc ( strlen ( oldstr ) - strlen ( substr ) + strlen ( replacement ) + 1 ); |
39 |
| - /*failed to alloc mem, free old string and return NULL */ |
40 |
| - if ( newstr == NULL ){ |
41 |
| - free (oldstr); |
42 |
| - return NULL; |
43 |
| - } |
44 |
| - memcpy ( newstr, oldstr, tok - oldstr ); |
45 |
| - memcpy ( newstr + (tok - oldstr), replacement, strlen ( replacement ) ); |
46 |
| - memcpy ( newstr + (tok - oldstr) + strlen( replacement ), tok + strlen ( substr ), strlen ( oldstr ) - strlen ( substr ) - ( tok - oldstr ) ); |
47 |
| - memset ( newstr + strlen ( oldstr ) - strlen ( substr ) + strlen ( replacement ) , 0, 1 ); |
48 |
| - /* move back head right after the last replacement */ |
49 |
| - head = newstr + (tok - oldstr) + strlen( replacement ); |
50 |
| - free (oldstr); |
51 |
| - } |
52 |
| - return newstr; |
53 |
| -} |
54 |
| - |
55 |
| - |
56 | 24 | void
|
57 | 25 | ngx_http_modsecurity_log(void *log, const char* msg)
|
58 | 26 | {
|
59 |
| - char *new_log = NULL; |
60 |
| - |
61 | 27 | if (log == NULL) {
|
62 | 28 | return;
|
63 | 29 | }
|
64 | 30 |
|
65 |
| - new_log = str_replace(msg, "%", "_"); |
66 |
| - ngx_log_error(NGX_LOG_INFO, (ngx_log_t *)log, 0, new_log); |
67 |
| - free(new_log); |
| 31 | + ngx_log_error(NGX_LOG_INFO, (ngx_log_t *)log, 0, "%s", msg); |
68 | 32 | }
|
69 | 33 |
|
70 | 34 |
|
|
0 commit comments