Skip to content

Commit

Permalink
nginx 1.23.3
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Dec 17, 2022
2 parents 9b937c7 + 9526873 commit 4a02e1e
Show file tree
Hide file tree
Showing 19 changed files with 192 additions and 63 deletions.
17 changes: 17 additions & 0 deletions nginx/CHANGES
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@

Changes with nginx 1.23.3 13 Dec 2022

*) Bugfix: an error might occur when reading PROXY protocol version 2
header with large number of TLVs.

*) Bugfix: a segmentation fault might occur in a worker process if SSI
was used to process subrequests created by other modules.
Thanks to Ciel Zhao.

*) Workaround: when a hostname used in the "listen" directive resolves
to multiple addresses, nginx now ignores duplicates within these
addresses.

*) Bugfix: nginx might hog CPU during unbuffered proxying if SSL
connections to backends were used.


Changes with nginx 1.23.2 19 Oct 2022

*) Security: processing of a specially crafted mp4 file by the
Expand Down
18 changes: 18 additions & 0 deletions nginx/CHANGES.ru
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@

Изменения в nginx 1.23.3 13.12.2022

*) Исправление: при чтении заголовка протокола PROXY версии 2,
содержащего большое количество TLV, могла возникать ошибка.

*) Исправление: при использовании SSI для обработки подзапросов,
созданных другими модулями, в рабочем процессе мог произойти
segmentation fault.
Спасибо Ciel Zhao.

*) Изменение: теперь, если при преобразовании в адреса имени хоста,
указанного в директиве listen, возвращается несколько адресов, nginx
игнорирует дубликаты среди этих адресов.

*) Исправление: nginx мог нагружать процессор при небуферизированном
проксировании, если использовались SSL-соединения с бэкендами.


Изменения в nginx 1.23.2 19.10.2022

*) Безопасность: обработка специально созданного mp4-файла модулем
Expand Down
4 changes: 2 additions & 2 deletions nginx/src/core/nginx.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// version number format
// 1'015'005

#define nginx_version 1023002
#define NGINX_VERSION "1.23.2"
#define nginx_version 1023003
#define NGINX_VERSION "1.23.3"
#define NGINX_VER "nginx/" NGINX_VERSION

// nginx 1.7之后添加--build=Name选项
Expand Down
15 changes: 8 additions & 7 deletions nginx/src/core/ngx_proxy_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ ngx_proxy_protocol_read(ngx_connection_t *c, u_char *buf, u_char *last)

// v2, binary
if (len >= sizeof(ngx_proxy_protocol_header_t)
&& memcmp(p, signature, sizeof(signature) - 1) == 0)
&& ngx_memcmp(p, signature, sizeof(signature) - 1) == 0)
{
return ngx_proxy_protocol_v2_read(c, buf, last);
}
Expand Down Expand Up @@ -305,8 +305,9 @@ ngx_proxy_protocol_write(ngx_connection_t *c, u_char *buf, u_char *last)
{
ngx_uint_t port, lport;

//#define NGX_PROXY_PROTOCOL_MAX_HEADER 107
if (last - buf < NGX_PROXY_PROTOCOL_MAX_HEADER) {
if (last - buf < NGX_PROXY_PROTOCOL_V1_MAX_HEADER) {
ngx_log_error(NGX_LOG_ALERT, c->log, 0,
"too small buffer for PROXY protocol");
return NULL;
}

Expand Down Expand Up @@ -419,11 +420,11 @@ ngx_proxy_protocol_v2_read(ngx_connection_t *c, u_char *buf, u_char *last)

src_sockaddr.sockaddr_in.sin_family = AF_INET;
src_sockaddr.sockaddr_in.sin_port = 0;
memcpy(&src_sockaddr.sockaddr_in.sin_addr, in->src_addr, 4);
ngx_memcpy(&src_sockaddr.sockaddr_in.sin_addr, in->src_addr, 4);

dst_sockaddr.sockaddr_in.sin_family = AF_INET;
dst_sockaddr.sockaddr_in.sin_port = 0;
memcpy(&dst_sockaddr.sockaddr_in.sin_addr, in->dst_addr, 4);
ngx_memcpy(&dst_sockaddr.sockaddr_in.sin_addr, in->dst_addr, 4);

pp->src_port = ngx_proxy_protocol_parse_uint16(in->src_port);
pp->dst_port = ngx_proxy_protocol_parse_uint16(in->dst_port);
Expand All @@ -446,11 +447,11 @@ ngx_proxy_protocol_v2_read(ngx_connection_t *c, u_char *buf, u_char *last)

src_sockaddr.sockaddr_in6.sin6_family = AF_INET6;
src_sockaddr.sockaddr_in6.sin6_port = 0;
memcpy(&src_sockaddr.sockaddr_in6.sin6_addr, in6->src_addr, 16);
ngx_memcpy(&src_sockaddr.sockaddr_in6.sin6_addr, in6->src_addr, 16);

dst_sockaddr.sockaddr_in6.sin6_family = AF_INET6;
dst_sockaddr.sockaddr_in6.sin6_port = 0;
memcpy(&dst_sockaddr.sockaddr_in6.sin6_addr, in6->dst_addr, 16);
ngx_memcpy(&dst_sockaddr.sockaddr_in6.sin6_addr, in6->dst_addr, 16);

pp->src_port = ngx_proxy_protocol_parse_uint16(in6->src_port);
pp->dst_port = ngx_proxy_protocol_parse_uint16(in6->dst_port);
Expand Down
3 changes: 2 additions & 1 deletion nginx/src/core/ngx_proxy_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#include <ngx_core.h>


#define NGX_PROXY_PROTOCOL_MAX_HEADER 107
#define NGX_PROXY_PROTOCOL_V1_MAX_HEADER 107
#define NGX_PROXY_PROTOCOL_MAX_HEADER 4096


struct ngx_proxy_protocol_s {
Expand Down
6 changes: 3 additions & 3 deletions nginx/src/core/ngx_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ ngx_copy(u_char *dst, u_char *src, size_t len)

// 内存移动,应该使用ngx_movemem
// 与c函数不一样,它返回移动后的地址,可以简化连续移动内存
#define ngx_memmove(dst, src, n) (void) memmove(dst, src, n)
#define ngx_movemem(dst, src, n) (((u_char *) memmove(dst, src, n)) + (n))
#define ngx_memmove(dst, src, n) (void) memmove(dst, src, n)
#define ngx_movemem(dst, src, n) (((u_char *) memmove(dst, src, n)) + (n))


/* msvc and icc7 compile memcmp() to the inline loop */
#define ngx_memcmp(s1, s2, n) memcmp((const char *) s1, (const char *) s2, n)
#define ngx_memcmp(s1, s2, n) memcmp(s1, s2, n)


// 拷贝字符串
Expand Down
9 changes: 7 additions & 2 deletions nginx/src/event/ngx_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
// 1.15.2新增部分检查代码
#if (NGX_HAVE_REUSEPORT)
ngx_uint_t i;
ngx_core_conf_t *ccf;
ngx_listening_t *ls;
#endif

Expand Down Expand Up @@ -691,7 +692,9 @@ ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)

#if (NGX_HAVE_REUSEPORT)

if (!ngx_test_config) {
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);

if (!ngx_test_config && ccf->master) {

ls = cycle->listening.elts;
for (i = 0; i < cycle->listening.nelts; i++) {
Expand Down Expand Up @@ -1181,7 +1184,9 @@ ngx_event_process_init(ngx_cycle_t *cycle)
rev->deferred_accept = ls[i].deferred_accept;
#endif

if (!(ngx_event_flags & NGX_USE_IOCP_EVENT)) {
if (!(ngx_event_flags & NGX_USE_IOCP_EVENT)
&& cycle->old_cycle)
{
if (ls[i].previous) {

/*
Expand Down
7 changes: 6 additions & 1 deletion nginx/src/event/ngx_event_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,7 @@ ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size)
#endif

if (c->ssl->last == NGX_ERROR) {
c->read->ready = 0;
c->read->error = 1;
return NGX_ERROR;
}
Expand Down Expand Up @@ -2295,6 +2296,7 @@ ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size)
#if (NGX_HAVE_FIONREAD)

if (ngx_socket_nread(c->fd, &c->read->available) == -1) {
c->read->ready = 0;
c->read->error = 1;
ngx_connection_error(c, ngx_socket_errno,
ngx_socket_nread_n " failed");
Expand Down Expand Up @@ -2331,6 +2333,7 @@ ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size)
return 0;

case NGX_ERROR:
c->read->ready = 0;
c->read->error = 1;

/* fall through */
Expand All @@ -2351,6 +2354,7 @@ ngx_ssl_recv_early(ngx_connection_t *c, u_char *buf, size_t size)
size_t readbytes;

if (c->ssl->last == NGX_ERROR) {
c->read->ready = 0;
c->read->error = 1;
return NGX_ERROR;
}
Expand Down Expand Up @@ -2450,6 +2454,7 @@ ngx_ssl_recv_early(ngx_connection_t *c, u_char *buf, size_t size)
return 0;

case NGX_ERROR:
c->read->ready = 0;
c->read->error = 1;

/* fall through */
Expand Down Expand Up @@ -3045,7 +3050,7 @@ ngx_ssl_sendfile(ngx_connection_t *c, ngx_buf_t *file, size_t size)
n = SSL_sendfile(c->ssl->connection, file->file->fd, file->file_pos,
size, flags);

ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_sendfile: %d", n);
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_sendfile: %z", n);

if (n > 0) {

Expand Down
29 changes: 28 additions & 1 deletion nginx/src/http/modules/ngx_http_ssi_filter_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ static ngx_http_variable_t ngx_http_ssi_vars[] = {
static ngx_int_t
ngx_http_ssi_header_filter(ngx_http_request_t *r)
{
ngx_http_ssi_ctx_t *ctx;
ngx_http_ssi_ctx_t *ctx, *mctx;
ngx_http_ssi_loc_conf_t *slcf;

slcf = ngx_http_get_module_loc_conf(r, ngx_http_ssi_filter_module);
Expand All @@ -341,6 +341,8 @@ ngx_http_ssi_header_filter(ngx_http_request_t *r)
return ngx_http_next_header_filter(r);
}

mctx = ngx_http_get_module_ctx(r->main, ngx_http_ssi_filter_module);

ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_ssi_ctx_t));
if (ctx == NULL) {
return NGX_ERROR;
Expand All @@ -367,6 +369,26 @@ ngx_http_ssi_header_filter(ngx_http_request_t *r)
r->filter_need_in_memory = 1;

if (r == r->main) {

if (mctx) {

/*
* if there was a shared context previously used as main,
* copy variables and blocks
*/

ctx->variables = mctx->variables;
ctx->blocks = mctx->blocks;

#if (NGX_PCRE)
ctx->ncaptures = mctx->ncaptures;
ctx->captures = mctx->captures;
ctx->captures_data = mctx->captures_data;
#endif

mctx->shared = 0;
}

ngx_http_clear_content_length(r);
ngx_http_clear_accept_ranges(r);

Expand All @@ -379,6 +401,10 @@ ngx_http_ssi_header_filter(ngx_http_request_t *r)
} else {
ngx_http_weak_etag(r);
}

} else if (mctx == NULL) {
ngx_http_set_ctx(r->main, ctx, ngx_http_ssi_filter_module);
ctx->shared = 1;
}

return ngx_http_next_header_filter(r);
Expand All @@ -405,6 +431,7 @@ ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
ctx = ngx_http_get_module_ctx(r, ngx_http_ssi_filter_module);

if (ctx == NULL
|| (ctx->shared && r == r->main)
|| (in == NULL
&& ctx->buf == NULL
&& ctx->in == NULL
Expand Down
1 change: 1 addition & 0 deletions nginx/src/http/modules/ngx_http_ssi_filter_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ typedef struct {
u_char *captures_data;
#endif

unsigned shared:1;
unsigned conditional:2;
unsigned encoding:2;
unsigned block:1;
Expand Down
15 changes: 14 additions & 1 deletion nginx/src/http/ngx_http_core_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -4759,7 +4759,7 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)

ngx_str_t *value, size;
ngx_url_t u;
ngx_uint_t n;
ngx_uint_t n, i;
ngx_http_listen_opt_t lsopt;

// server有listen的标志位
Expand Down Expand Up @@ -5112,6 +5112,16 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)

// 1.15.10,range listen
for (n = 0; n < u.naddrs; n++) {

for (i = 0; i < n; i++) {
if (ngx_cmp_sockaddr(u.addrs[n].sockaddr, u.addrs[n].socklen,
u.addrs[i].sockaddr, u.addrs[i].socklen, 0)
== NGX_OK)
{
goto next;
}
}

lsopt.sockaddr = u.addrs[n].sockaddr;
lsopt.socklen = u.addrs[n].socklen;
lsopt.addr_text = u.addrs[n].name;
Expand All @@ -5120,6 +5130,9 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (ngx_http_add_listen(cf, cscf, &lsopt) != NGX_OK) {
return NGX_CONF_ERROR;
}

next:
continue;
}

return NGX_CONF_OK;
Expand Down
47 changes: 35 additions & 12 deletions nginx/src/mail/ngx_mail_core_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ ngx_mail_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_str_t *value, size;
ngx_url_t u;
ngx_uint_t i, n, m;
ngx_mail_listen_t *ls, *als;
ngx_mail_listen_t *ls, *als, *nls;
ngx_mail_module_t *module;
ngx_mail_core_main_conf_t *cmcf;

Expand All @@ -333,7 +333,7 @@ ngx_mail_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)

cmcf = ngx_mail_conf_get_module_main_conf(cf, ngx_mail_core_module);

ls = ngx_array_push_n(&cmcf->listen, u.naddrs);
ls = ngx_array_push(&cmcf->listen);
if (ls == NULL) {
return NGX_CONF_ERROR;
}
Expand Down Expand Up @@ -568,30 +568,53 @@ ngx_mail_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR;
}

als = cmcf->listen.elts;

for (n = 0; n < u.naddrs; n++) {
ls[n] = ls[0];

ls[n].sockaddr = u.addrs[n].sockaddr;
ls[n].socklen = u.addrs[n].socklen;
ls[n].addr_text = u.addrs[n].name;
ls[n].wildcard = ngx_inet_wildcard(ls[n].sockaddr);
for (i = 0; i < n; i++) {
if (ngx_cmp_sockaddr(u.addrs[n].sockaddr, u.addrs[n].socklen,
u.addrs[i].sockaddr, u.addrs[i].socklen, 0)
== NGX_OK)
{
goto next;
}
}

if (n != 0) {
nls = ngx_array_push(&cmcf->listen);
if (nls == NULL) {
return NGX_CONF_ERROR;
}

*nls = *ls;

} else {
nls = ls;
}

for (i = 0; i < cmcf->listen.nelts - u.naddrs + n; i++) {
nls->sockaddr = u.addrs[n].sockaddr;
nls->socklen = u.addrs[n].socklen;
nls->addr_text = u.addrs[n].name;
nls->wildcard = ngx_inet_wildcard(nls->sockaddr);

als = cmcf->listen.elts;

for (i = 0; i < cmcf->listen.nelts - 1; i++) {

if (ngx_cmp_sockaddr(als[i].sockaddr, als[i].socklen,
ls[n].sockaddr, ls[n].socklen, 1)
nls->sockaddr, nls->socklen, 1)
!= NGX_OK)
{
continue;
}

ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"duplicate \"%V\" address and port pair",
&ls[n].addr_text);
&nls->addr_text);
return NGX_CONF_ERROR;
}

next:
continue;
}

return NGX_CONF_OK;
Expand Down
Loading

0 comments on commit 4a02e1e

Please sign in to comment.