[PATCH 05 of 10] SSL: added buffer checks to ngx_ssl_send_chain()
Maxim Dounin
mdounin at mdounin.ru
Tue Nov 24 00:27:08 UTC 2026
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1795479774 -10800
# Tue Nov 24 03:22:54 2026 +0300
# Node ID 719ce1a193bf691cf9d3bc933d81cb5755922b33
# Parent e1b8bf142baffa8dd81f11e47d654f63be405bdf
SSL: added buffer checks to ngx_ssl_send_chain().
Similarly to buffer checks present in ngx_http_write_filter() and
ngx_output_chain(), these checks are expected to catch invalid buffers
if passed to the SSL layer. Notably, this is expected to improve the
safety of HTTP/2, which performs complex buffer manipulations after the
write filter checks.
diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c
--- a/src/event/ngx_event_openssl.c
+++ b/src/event/ngx_event_openssl.c
@@ -3191,6 +3191,42 @@ ngx_ssl_send_chain(ngx_connection_t *c,
continue;
}
+ if (ngx_buf_size(in->buf) == 0) {
+ ngx_log_error(NGX_LOG_ALERT, c->log, 0,
+ "zero size buf in ssl send chain "
+ "t:%d r:%d f:%d %p %p-%p %p %O-%O",
+ in->buf->temporary,
+ in->buf->recycled,
+ in->buf->in_file,
+ in->buf->start,
+ in->buf->pos,
+ in->buf->last,
+ in->buf->file,
+ in->buf->file_pos,
+ in->buf->file_last);
+
+ ngx_debug_point();
+ return NGX_CHAIN_ERROR;
+ }
+
+ if (ngx_buf_size(in->buf) < 0) {
+ ngx_log_error(NGX_LOG_ALERT, c->log, 0,
+ "negative size buf in ssl send chain "
+ "t:%d r:%d f:%d %p %p-%p %p %O-%O",
+ in->buf->temporary,
+ in->buf->recycled,
+ in->buf->in_file,
+ in->buf->start,
+ in->buf->pos,
+ in->buf->last,
+ in->buf->file,
+ in->buf->file_pos,
+ in->buf->file_last);
+
+ ngx_debug_point();
+ return NGX_CHAIN_ERROR;
+ }
+
n = ngx_ssl_write(c, in->buf->pos, in->buf->last - in->buf->pos);
if (n == NGX_ERROR) {
@@ -3255,6 +3291,42 @@ ngx_ssl_send_chain(ngx_connection_t *c,
continue;
}
+ if (ngx_buf_size(in->buf) == 0) {
+ ngx_log_error(NGX_LOG_ALERT, c->log, 0,
+ "zero size buf in ssl send chain "
+ "t:%d r:%d f:%d %p %p-%p %p %O-%O",
+ in->buf->temporary,
+ in->buf->recycled,
+ in->buf->in_file,
+ in->buf->start,
+ in->buf->pos,
+ in->buf->last,
+ in->buf->file,
+ in->buf->file_pos,
+ in->buf->file_last);
+
+ ngx_debug_point();
+ return NGX_CHAIN_ERROR;
+ }
+
+ if (ngx_buf_size(in->buf) < 0) {
+ ngx_log_error(NGX_LOG_ALERT, c->log, 0,
+ "negative size buf in ssl send chain "
+ "t:%d r:%d f:%d %p %p-%p %p %O-%O",
+ in->buf->temporary,
+ in->buf->recycled,
+ in->buf->in_file,
+ in->buf->start,
+ in->buf->pos,
+ in->buf->last,
+ in->buf->file,
+ in->buf->file_pos,
+ in->buf->file_last);
+
+ ngx_debug_point();
+ return NGX_CHAIN_ERROR;
+ }
+
if (in->buf->in_file && c->ssl->sendfile) {
flush = 1;
break;
More information about the nginx-devel
mailing list