From 6162865d5a398d96a08adabe216b292ee3bf4afa Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 16 Feb 2018 20:57:30 +0000 Subject: [PATCH] bump max line length to 16K for incoming mail. SMTP commands are still limited to LINE_MAX. ok gilles@ --- usr.sbin/smtpd/rfc2822.h | 4 ++-- usr.sbin/smtpd/smtp_session.c | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/usr.sbin/smtpd/rfc2822.h b/usr.sbin/smtpd/rfc2822.h index 48bdf6de495..2132cca61cc 100644 --- a/usr.sbin/smtpd/rfc2822.h +++ b/usr.sbin/smtpd/rfc2822.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rfc2822.h,v 1.4 2015/11/05 08:55:09 gilles Exp $ */ +/* $OpenBSD: rfc2822.h,v 1.5 2018/02/16 20:57:30 eric Exp $ */ /* * Copyright (c) 2014 Gilles Chehade @@ -19,7 +19,7 @@ #ifndef _RFC2822_H_ #define _RFC2822_H_ -#define RFC2822_MAX_LINE_SIZE 4096 +#define RFC2822_MAX_LINE_SIZE 16384 struct rfc2822_line { TAILQ_ENTRY(rfc2822_line) next; diff --git a/usr.sbin/smtpd/smtp_session.c b/usr.sbin/smtpd/smtp_session.c index 61ed2cac853..ad64f94e4a8 100644 --- a/usr.sbin/smtpd/smtp_session.c +++ b/usr.sbin/smtpd/smtp_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtp_session.c,v 1.316 2018/02/09 09:29:03 eric Exp $ */ +/* $OpenBSD: smtp_session.c,v 1.317 2018/02/16 20:57:30 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -45,8 +45,9 @@ #include "log.h" #include "ssl.h" +#define SMTP_LINE_MAX 16384 #define DATA_HIWAT 65535 -#define APPEND_DOMAIN_BUFFER_SIZE 4096 +#define APPEND_DOMAIN_BUFFER_SIZE SMTP_LINE_MAX enum smtp_state { STATE_NEW = 0, @@ -1007,8 +1008,8 @@ smtp_io(struct io *io, int evt, void *arg) case IO_DATAIN: nextline: line = io_getline(s->io, &len); - if ((line == NULL && io_datalen(s->io) >= LINE_MAX) || - (line && len >= LINE_MAX)) { + if ((line == NULL && io_datalen(s->io) >= SMTP_LINE_MAX) || + (line && len >= SMTP_LINE_MAX)) { s->flags |= SF_BADINPUT; smtp_reply(s, "500 %s: Line too long", esc_code(ESC_STATUS_PERMFAIL, ESC_OTHER_STATUS)); @@ -1047,7 +1048,14 @@ smtp_io(struct io *io, int evt, void *arg) } /* Must be a command */ - (void)strlcpy(s->cmd, line, sizeof s->cmd); + if (strlcpy(s->cmd, line, sizeof(s->cmd)) >= sizeof(s->cmd)) { + s->flags |= SF_BADINPUT; + smtp_reply(s, "500 %s: Command line too long", + esc_code(ESC_STATUS_PERMFAIL, ESC_OTHER_STATUS)); + smtp_enter_state(s, STATE_QUIT); + io_set_write(io); + return; + } io_set_write(io); smtp_command(s, line); break; -- 2.20.1