From 533301e564187af35d739ab77e4d5285f18137b6 Mon Sep 17 00:00:00 2001 From: Hans Zandbelt Date: Wed, 5 Jun 2024 20:06:26 +0200 Subject: [PATCH] release 1.6.2: fix port detection with NGINX >= 1.27.0 oops: use local_sockaddr instead of the remote one Signed-off-by: Hans Zandbelt --- .cproject | 9 ++++----- src/server/nginx.c | 7 ++++--- test/check_nginx.c | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.cproject b/.cproject index aef997b..317acfb 100644 --- a/.cproject +++ b/.cproject @@ -18,7 +18,7 @@ - + @@ -86,7 +86,7 @@ - + @@ -190,11 +190,10 @@ make - clang-format true true - true + false make @@ -202,7 +201,7 @@ check true true - true + false diff --git a/src/server/nginx.c b/src/server/nginx.c index 5e434ed..8247204 100644 --- a/src/server/nginx.c +++ b/src/server/nginx.c @@ -105,10 +105,11 @@ static void _oauth2_nginx_port_copy(oauth2_nginx_request_context_t *ctx) struct sockaddr_in6 *sin6; #endif - switch (ctx->r->connection->sockaddr->sa_family) { + switch (ctx->r->connection->local_sockaddr->sa_family) { #if (NGX_HAVE_INET6) case AF_INET6: - sin6 = (struct sockaddr_in6 *)ctx->r->connection->sockaddr; + sin6 = + (struct sockaddr_in6 *)ctx->r->connection->local_sockaddr; port = ntohs(sin6->sin6_port); #endif #if (NGX_HAVE_UNIX_DOMAIN) @@ -116,7 +117,7 @@ static void _oauth2_nginx_port_copy(oauth2_nginx_request_context_t *ctx) port = 0; #endif default: /* AF_INET */ - sin = (struct sockaddr_in *)ctx->r->connection->sockaddr; + sin = (struct sockaddr_in *)ctx->r->connection->local_sockaddr; port = ntohs(sin->sin_port); } diff --git a/test/check_nginx.c b/test/check_nginx.c index eb86ac8..54b3b77 100644 --- a/test/check_nginx.c +++ b/test/check_nginx.c @@ -49,10 +49,10 @@ static void setup(void) _request->pool = ngx_create_pool(1024, NULL); _request->connection = oauth2_mem_alloc(sizeof(ngx_connection_t)); _request->connection->log = NULL; - _request->connection->sockaddr = + _request->connection->local_sockaddr = oauth2_mem_alloc(sizeof(struct sockaddr_in)); - _request->connection->sockaddr->sa_family = AF_INET; - ((struct sockaddr_in *)_request->connection->sockaddr)->sin_port = + _request->connection->local_sockaddr->sa_family = AF_INET; + ((struct sockaddr_in *)_request->connection->local_sockaddr)->sin_port = htons(8080); _request->http_connection = oauth2_mem_alloc(sizeof(ngx_http_connection_t));