Skip to content

Commit 407f2bc

Browse files
committed
Avoid allocation for server address
1 parent b94f2d3 commit 407f2bc

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/ngx_http_modsecurity_access.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,26 +147,20 @@ ngx_http_modsecurity_access_handler(ngx_http_request_t *r)
147147
#endif
148148

149149
ngx_str_t s;
150-
u_char addr[NGX_SOCKADDR_STRLEN];
151-
s.len = NGX_SOCKADDR_STRLEN;
152-
s.data = addr;
150+
u_char server_addr[NGX_SOCKADDR_STRLEN + 1];
151+
s.len = 0;
152+
s.data = server_addr;
153153
if (ngx_connection_local_sockaddr(r->connection, &s, 0) != NGX_OK) {
154154
return NGX_HTTP_INTERNAL_SERVER_ERROR;
155155
}
156-
157-
const char *server_addr = ngx_str_to_char(s, r->pool);
158-
if (server_addr == (char*)-1) {
159-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
160-
}
156+
server_addr[s.len] = '\0'; // ngx_str_t is not null terminated, so we have insert \0 manually
161157

162158
old_pool = ngx_http_modsecurity_pcre_malloc_init(r->pool);
163-
ret = msc_process_connection(ctx->modsec_transaction,
159+
msc_process_connection(ctx->modsec_transaction,
164160
client_addr, client_port,
165-
server_addr, server_port);
161+
(const char *) server_addr, server_port);
166162
ngx_http_modsecurity_pcre_malloc_done(old_pool);
167-
if (ret != 1){
168-
dd("Was not able to extract connection information.");
169-
}
163+
170164
/**
171165
*
172166
* FIXME: Check how we can finalize a request without crash nginx.

0 commit comments

Comments
 (0)