Skip to content

Commit f39e2a2

Browse files
defanatorzimmerle
authored andcommitted
Removed str_replace() function introduced in 2de9b2a.
Using the "%s" format for ngx_log_error() seems to be enough.
1 parent 3afe7b9 commit f39e2a2

File tree

1 file changed

+1
-37
lines changed

1 file changed

+1
-37
lines changed

src/ngx_http_modsecurity_log.c

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,50 +21,14 @@
2121
#include "ngx_http_modsecurity_common.h"
2222

2323

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-
5624
void
5725
ngx_http_modsecurity_log(void *log, const char* msg)
5826
{
59-
char *new_log = NULL;
60-
6127
if (log == NULL) {
6228
return;
6329
}
6430

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);
6832
}
6933

7034

0 commit comments

Comments
 (0)