Welcome! Log In Create A New Profile

Advanced

[nginx] Mail: fixed reading with fully filled buffer (ticket #2159).

Maxim Dounin
April 21, 2021 05:26PM
details: https://hg.nginx.org/nginx/rev/2851e4c7de03
branches:
changeset: 7829:2851e4c7de03
user: Maxim Dounin <mdounin@mdounin.ru>
date: Wed Apr 21 23:24:59 2021 +0300
description:
Mail: fixed reading with fully filled buffer (ticket #2159).

With SMTP pipelining, ngx_mail_read_command() can be called with s->buffer
without any space available, to parse additional commands received to the
buffer on previous calls. Previously, this resulted in recv() being called
with zero length, resulting in zero being returned, which was interpreted
as a connection close by the client, so nginx silently closed connection.

Fix is to avoid calling c->recv() if there is no free space in the buffer,
but continue parsing of the already received commands.

diffstat:

src/mail/ngx_mail_handler.c | 25 ++++++++++++++-----------
1 files changed, 14 insertions(+), 11 deletions(-)

diffs (38 lines):

diff -r c40f7a65c506 -r 2851e4c7de03 src/mail/ngx_mail_handler.c
--- a/src/mail/ngx_mail_handler.c Wed Apr 21 23:24:48 2021 +0300
+++ b/src/mail/ngx_mail_handler.c Wed Apr 21 23:24:59 2021 +0300
@@ -833,20 +833,23 @@ ngx_mail_read_command(ngx_mail_session_t
ngx_str_t l;
ngx_mail_core_srv_conf_t *cscf;

- n = c->recv(c, s->buffer->last, s->buffer->end - s->buffer->last);
+ if (s->buffer->last < s->buffer->end) {
+
+ n = c->recv(c, s->buffer->last, s->buffer->end - s->buffer->last);

- if (n == NGX_ERROR || n == 0) {
- ngx_mail_close_connection(c);
- return NGX_ERROR;
- }
+ if (n == NGX_ERROR || n == 0) {
+ ngx_mail_close_connection(c);
+ return NGX_ERROR;
+ }

- if (n > 0) {
- s->buffer->last += n;
- }
+ if (n > 0) {
+ s->buffer->last += n;
+ }

- if (n == NGX_AGAIN) {
- if (s->buffer->pos == s->buffer->last) {
- return NGX_AGAIN;
+ if (n == NGX_AGAIN) {
+ if (s->buffer->pos == s->buffer->last) {
+ return NGX_AGAIN;
+ }
}
}

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Mail: fixed reading with fully filled buffer (ticket #2159).

Maxim Dounin 350 April 21, 2021 05:26PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 257
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready