Welcome! Log In Create A New Profile

Advanced

[nginx] Mail: fixed handling of invalid SMTP commands split between reads.

Maxim Dounin
May 18, 2021 09:28PM
details: https://hg.nginx.org/nginx/rev/6a81d96d3733
branches:
changeset: 7836:6a81d96d3733
user: Maxim Dounin <mdounin@mdounin.ru>
date: Wed May 19 03:13:15 2021 +0300
description:
Mail: fixed handling of invalid SMTP commands split between reads.

Previously, if an invalid SMTP command was split between reads, nginx failed
to wait for LF before returning an error, and interpreted the rest of the
command received later as a separate command.

The sw_invalid state in ngx_mail_smtp_parse_command(), introduced in
04e43d03e153, did not work, since ngx_mail_smtp_auth_state() clears
s->state when returning an error due to NGX_MAIL_PARSE_INVALID_COMMAND.
And not clearing s->state will introduce another problem: the rest
of the command would trigger duplicate error when rest of the command is
received.

Fix is to return NGX_AGAIN from ngx_mail_smtp_parse_command() until full
command is received.

diffstat:

src/mail/ngx_mail_parse.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)

diffs (21 lines):

diff -r c72d8839f427 -r 6a81d96d3733 src/mail/ngx_mail_parse.c
--- a/src/mail/ngx_mail_parse.c Wed May 19 03:13:12 2021 +0300
+++ b/src/mail/ngx_mail_parse.c Wed May 19 03:13:15 2021 +0300
@@ -846,14 +846,14 @@ invalid:
for (p = s->buffer->pos; p < s->buffer->last; p++) {
if (*p == LF) {
s->state = sw_start;
- p++;
- break;
+ s->buffer->pos = p + 1;
+ return NGX_MAIL_PARSE_INVALID_COMMAND;
}
}

s->buffer->pos = p;

- return NGX_MAIL_PARSE_INVALID_COMMAND;
+ 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 handling of invalid SMTP commands split between reads.

Maxim Dounin 237 May 18, 2021 09:28PM



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

Online Users

Guests: 280
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