Skip to content

Commit

Permalink
Fixed obtaining of server_addr
Browse files Browse the repository at this point in the history
Closes #167.

While here, adjusted related code to use nginx own macros instead
of direct functions (htons, inet_ntoa).
  • Loading branch information
defanator authored and zimmerle committed Dec 9, 2019
1 parent 4ca5e15 commit bba7c8c
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/ngx_http_modsecurity_rewrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,27 @@ ngx_http_modsecurity_rewrite_handler(ngx_http_request_t *r)
* erliest phase that nginx allow us to attach those kind of hooks.
*
*/
int client_port = htons(((struct sockaddr_in *) connection->sockaddr)->sin_port);
int server_port = htons(((struct sockaddr_in *) connection->listening->sockaddr)->sin_port);
int client_port = ngx_inet_get_port(connection->sockaddr);
int server_port = ngx_inet_get_port(connection->local_sockaddr);

const char *client_addr = ngx_str_to_char(addr_text, r->pool);
if (client_addr == (char*)-1) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
const char *server_addr = inet_ntoa(((struct sockaddr_in *) connection->sockaddr)->sin_addr);

ngx_str_t s;
u_char addr[NGX_SOCKADDR_STRLEN];
s.len = NGX_SOCKADDR_STRLEN;
s.data = addr;
if (ngx_connection_local_sockaddr(r->connection, &s, 0) != NGX_OK) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}

const char *server_addr = ngx_str_to_char(s, r->pool);
if (server_addr == (char*)-1) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}

old_pool = ngx_http_modsecurity_pcre_malloc_init(r->pool);
ret = msc_process_connection(ctx->modsec_transaction,
client_addr, client_port,
Expand Down

0 comments on commit bba7c8c

Please sign in to comment.