From a215a7d1a1c5eab40f6896fc07931a81d5504f18 Mon Sep 17 00:00:00 2001
From: maminjie <maminjie1@huawei.com>
Date: Sat, 27 Mar 2021 11:18:23 +0800
Subject: [PATCH] Fix bugs in smtp server

reference to: https://github.com/dovecot/core/pull/120
---
 src/lib-smtp/smtp-server-cmd-data.c | 2 +-
 src/lib-smtp/smtp-server-cmd-helo.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/lib-smtp/smtp-server-cmd-data.c b/src/lib-smtp/smtp-server-cmd-data.c
index 2650643..a7db425 100644
--- a/src/lib-smtp/smtp-server-cmd-data.c
+++ b/src/lib-smtp/smtp-server-cmd-data.c
@@ -654,7 +654,7 @@ void smtp_server_cmd_bdat(struct smtp_server_cmd_ctx *cmd,
 		}
 	}
 
-	if (ret > 0 || size > 0) {
+	if (ret > 0 || (size > 0 && conn->smtp_parser)) {
 		/* read/skip data even in case of error, as long as size is
 		   known */
 		input = smtp_command_parse_data_with_size(conn->smtp_parser,
diff --git a/src/lib-smtp/smtp-server-cmd-helo.c b/src/lib-smtp/smtp-server-cmd-helo.c
index 330ceaa..40ba328 100644
--- a/src/lib-smtp/smtp-server-cmd-helo.c
+++ b/src/lib-smtp/smtp-server-cmd-helo.c
@@ -155,7 +155,7 @@ smtp_server_cmd_ehlo_reply_create(struct smtp_server_cmd_ctx *cmd)
 	unsigned int extra_caps_count, i, j;
 	struct smtp_server_reply *reply;
 
-	i_assert(cmd->cmd->reg->func == smtp_server_cmd_ehlo);
+	i_assert(cmd->cmd->reg->func == smtp_server_cmd_ehlo || cmd->cmd->reg->func == smtp_server_cmd_helo);
 	reply = smtp_server_reply_create_ehlo(cmd->cmd);
 
 	if (helo_data->helo.old_smtp)
-- 
2.23.0

