[nginx] Mail: handling of pipelined commands which cross buffer ...
Maxim Dounin
mdounin at mdounin.ru
Sat Mar 30 04:59:46 UTC 2024
details: http://freenginx.org/hg/nginx/rev/d7fd0acdea64
branches:
changeset: 9235:d7fd0acdea64
user: Maxim Dounin <mdounin at mdounin.ru>
date: Sat Mar 30 05:05:31 2024 +0300
description:
Mail: handling of pipelined commands which cross buffer boundary.
Previously, pipelined commands which cross buffer boundary were rejected
as too long, even if the command itself was short enough to be handled
within the client buffer.
Fix is to move non-processed commands to the start of the buffer after
the previous command is fully processed.
diffstat:
src/mail/ngx_mail_imap_handler.c | 7 +++++++
src/mail/ngx_mail_pop3_handler.c | 7 +++++++
src/mail/ngx_mail_smtp_handler.c | 7 +++++++
3 files changed, 21 insertions(+), 0 deletions(-)
diffs (72 lines):
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
@@ -102,6 +102,7 @@ void
ngx_mail_imap_auth_state(ngx_event_t *rev)
{
u_char *p;
+ size_t n;
ngx_int_t rc;
ngx_uint_t tag;
ngx_connection_t *c;
@@ -285,6 +286,12 @@ ngx_mail_imap_auth_state(ngx_event_t *re
if (s->buffer->pos == s->buffer->last) {
s->buffer->pos = s->buffer->start;
s->buffer->last = s->buffer->start;
+
+ } else {
+ n = s->buffer->last - s->buffer->pos;
+ ngx_memmove(s->buffer->start, s->buffer->pos, n);
+ s->buffer->pos = s->buffer->start;
+ s->buffer->last = s->buffer->start + n;
}
s->tag.len = 0;
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
@@ -119,6 +119,7 @@ ngx_mail_pop3_init_protocol(ngx_event_t
void
ngx_mail_pop3_auth_state(ngx_event_t *rev)
{
+ size_t n;
ngx_int_t rc;
ngx_connection_t *c;
ngx_mail_session_t *s;
@@ -291,6 +292,12 @@ ngx_mail_pop3_auth_state(ngx_event_t *re
if (s->buffer->pos == s->buffer->last) {
s->buffer->pos = s->buffer->start;
s->buffer->last = s->buffer->start;
+
+ } else {
+ n = s->buffer->last - s->buffer->pos;
+ ngx_memmove(s->buffer->start, s->buffer->pos, n);
+ s->buffer->pos = s->buffer->start;
+ s->buffer->last = s->buffer->start + n;
}
if (s->state) {
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
@@ -430,6 +430,7 @@ ngx_mail_smtp_create_buffer(ngx_mail_ses
void
ngx_mail_smtp_auth_state(ngx_event_t *rev)
{
+ size_t n;
ngx_int_t rc;
ngx_connection_t *c;
ngx_mail_session_t *s;
@@ -577,6 +578,12 @@ ngx_mail_smtp_auth_state(ngx_event_t *re
if (s->buffer->pos == s->buffer->last) {
s->buffer->pos = s->buffer->start;
s->buffer->last = s->buffer->start;
+
+ } else {
+ n = s->buffer->last - s->buffer->pos;
+ ngx_memmove(s->buffer->start, s->buffer->pos, n);
+ s->buffer->pos = s->buffer->start;
+ s->buffer->last = s->buffer->start + n;
}
if (s->state) {
More information about the nginx-devel
mailing list