From: eric Date: Wed, 15 May 2019 05:02:43 +0000 (+0000) Subject: normalize newlines when reading the message X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=410c8eb677b0956e93ab77ac60ae6aba7817dfc0;p=openbsd normalize newlines when reading the message spotted by martijn@ ok martijn@ gilles@ --- diff --git a/usr.sbin/smtpd/smtpc.c b/usr.sbin/smtpd/smtpc.c index d6bb2c8321e..2373aa76d49 100644 --- a/usr.sbin/smtpd/smtpc.c +++ b/usr.sbin/smtpd/smtpc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpc.c,v 1.4 2018/09/20 11:42:28 eric Exp $ */ +/* $OpenBSD: smtpc.c,v 1.5 2019/05/15 05:02:43 eric Exp $ */ /* * Copyright (c) 2018 Eric Faurot @@ -283,8 +283,15 @@ parse_message(FILE *ifp) break; fatal("getline"); } + + if (len >= 2 && line[len - 2] == '\r' && line[len - 1] == '\n') + line[--len - 1] = '\n'; + if (fwrite(line, 1, len, mail.fp) != len) - fatal("frwite"); + fatal("fwrite"); + + if (line[len - 1] != '\n' && fputc('\n', mail.fp) == EOF) + fatal("fputc"); } fclose(ifp);