[PATCH 02 of 10] Mail: handling of read buffer filled with commands
Maxim Dounin
mdounin at mdounin.ru
Fri Mar 15 18:14:16 UTC 2024
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1710526241 -10800
# Fri Mar 15 21:10:41 2024 +0300
# Node ID 1d26e6050416a6c8a86d83119d894f7f9f4f5a94
# Parent dc9a4c5573411f8f6115db56d201ce0fa2c002fc
Mail: handling of read buffer filled with commands.
If the whole read buffer was filled with commands during authentication,
exactly matching the buffer boundary, this did not cause the "client sent
too long command" error, but might result in read events being disabled
for the connection, notably with level-triggered event methods, leading
to a connection hang.
Fix is to ensure that s->blocked is set in case of c->read->ready, so
command reading is resumed after sending responses to previous commands.
diff --git a/src/mail/ngx_mail_imap_handler.c b/src/mail/ngx_mail_imap_handler.c
--- a/src/mail/ngx_mail_imap_handler.c
+++ b/src/mail/ngx_mail_imap_handler.c
@@ -226,7 +226,7 @@ ngx_mail_imap_auth_state(ngx_event_t *re
ngx_str_set(&s->out, imap_next);
}
- if (s->buffer->pos < s->buffer->last) {
+ if (s->buffer->pos < s->buffer->last || c->read->ready) {
s->blocked = 1;
}
diff --git a/src/mail/ngx_mail_pop3_handler.c b/src/mail/ngx_mail_pop3_handler.c
--- a/src/mail/ngx_mail_pop3_handler.c
+++ b/src/mail/ngx_mail_pop3_handler.c
@@ -262,7 +262,7 @@ ngx_mail_pop3_auth_state(ngx_event_t *re
}
}
- if (s->buffer->pos < s->buffer->last) {
+ if (s->buffer->pos < s->buffer->last || c->read->ready) {
s->blocked = 1;
}
diff --git a/src/mail/ngx_mail_smtp_handler.c b/src/mail/ngx_mail_smtp_handler.c
--- a/src/mail/ngx_mail_smtp_handler.c
+++ b/src/mail/ngx_mail_smtp_handler.c
@@ -550,7 +550,7 @@ ngx_mail_smtp_auth_state(ngx_event_t *re
}
}
- if (s->buffer->pos < s->buffer->last) {
+ if (s->buffer->pos < s->buffer->last || c->read->ready) {
s->blocked = 1;
}
More information about the nginx-devel
mailing list