From 707c272e0cf1525b10d80ac471d72c2a3bf6740f Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 24 Apr 2020 11:34:07 +0000 Subject: strip trailing CRs at smtp level rather than io level ok millert@ --- bounce.c | 6 +++++- iobuf.c | 7 +++---- lka_filter.c | 4 ++-- mta_session.c | 6 +++++- smtp_client.c | 6 +++++- smtp_session.c | 6 +++++- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/bounce.c b/bounce.c index 4ce0ff71..e6fc5578 100644 --- a/bounce.c +++ b/bounce.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bounce.c,v 1.81 2019/11/25 12:11:26 eric Exp $ */ +/* $OpenBSD: bounce.c,v 1.82 2020/04/24 11:34:07 eric Exp $ */ /* * Copyright (c) 2009 Gilles Chehade @@ -728,6 +728,10 @@ bounce_io(struct io *io, int evt, void *arg) if (line == NULL) break; + /* Strip trailing '\r' */ + if (len && line[len - 1] == '\r') + line[--len] = '\0'; + log_trace(TRACE_BOUNCE, "bounce: %p: <<< %s", s, line); if ((error = parse_smtp_response(line, len, &msg, &cont))) { diff --git a/iobuf.c b/iobuf.c index f5d8b20a..e8a178ab 100644 --- a/iobuf.c +++ b/iobuf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: iobuf.c,v 1.12 2019/10/03 07:03:23 gilles Exp $ */ +/* $OpenBSD: iobuf.c,v 1.13 2020/04/24 11:34:07 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot * @@ -174,10 +174,9 @@ iobuf_getline(struct iobuf *iobuf, size_t *rlen) * the next call to iobuf_normalize() or iobuf_extend(). */ iobuf_drop(iobuf, i + 1); - len = (i && buf[i - 1] == '\r') ? i - 1 : i; - buf[len] = '\0'; + buf[i] = '\0'; if (rlen) - *rlen = len; + *rlen = i; return (buf); } diff --git a/lka_filter.c b/lka_filter.c index 715ab831..bcb76f89 100644 --- a/lka_filter.c +++ b/lka_filter.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka_filter.c,v 1.61 2020/04/17 14:20:13 eric Exp $ */ +/* $OpenBSD: lka_filter.c,v 1.62 2020/04/24 11:34:07 eric Exp $ */ /* * Copyright (c) 2018 Gilles Chehade @@ -851,7 +851,7 @@ filter_data_internal(struct filter_session *fs, uint64_t token, uint64_t reqid, /* no filter_entry, we either had none or reached end of chain */ if (filter_entry == NULL) { - io_printf(fs->io, "%s\r\n", line); + io_printf(fs->io, "%s\n", line); return; } diff --git a/mta_session.c b/mta_session.c index 8710d379..fa7c7e1c 100644 --- a/mta_session.c +++ b/mta_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mta_session.c,v 1.134 2020/04/10 19:28:57 beck Exp $ */ +/* $OpenBSD: mta_session.c,v 1.135 2020/04/24 11:34:07 eric Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard @@ -1257,6 +1257,10 @@ mta_io(struct io *io, int evt, void *arg) return; } + /* Strip trailing '\r' */ + if (len && line[len - 1] == '\r') + line[--len] = '\0'; + log_trace(TRACE_MTA, "mta: %p: <<< %s", s, line); mta_report_protocol_server(s, line); diff --git a/smtp_client.c b/smtp_client.c index 528f48b7..8e146e1b 100644 --- a/smtp_client.c +++ b/smtp_client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtp_client.c,v 1.13 2020/02/24 23:54:27 millert Exp $ */ +/* $OpenBSD: smtp_client.c,v 1.14 2020/04/24 11:34:07 eric Exp $ */ /* * Copyright (c) 2018 Eric Faurot @@ -680,6 +680,10 @@ smtp_client_readline(struct smtp_client *proto) return 0; } + /* Strip trailing '\r' */ + if (len && line[len - 1] == '\r') + line[--len] = '\0'; + log_trace(TRACE_SMTPCLT, "%p: <<< %s", proto, line); /* Validate SMTP */ diff --git a/smtp_session.c b/smtp_session.c index d6c45b92..5ea9f89e 100644 --- a/smtp_session.c +++ b/smtp_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtp_session.c,v 1.425 2020/03/15 16:34:57 millert Exp $ */ +/* $OpenBSD: smtp_session.c,v 1.426 2020/04/24 11:34:07 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -1132,6 +1132,10 @@ smtp_io(struct io *io, int evt, void *arg) if (line == NULL) return; + /* Strip trailing '\r' */ + if (len && line[len - 1] == '\r') + line[--len] = '\0'; + /* Message body */ eom = 0; if (s->state == STATE_BODY) { -- cgit v1.2.3-59-g8ed1b