Re: mutt/2094: ESMTP patch: newline conversion and faulty error checking
The following reply was made to PR mutt/2094; it has been noted by GNATS.
From: Ralf Wildenhues <wildenhues@xxxxxxxxxxxxxxx>
To: bug-any@xxxxxxxxxxxxx
Cc:
Subject: Re: mutt/2094: ESMTP patch: newline conversion and faulty error
checking
Date: Tue, 27 Sep 2005 19:16:36 +0200
* Ralf Wildenhues wrote on Tue, Sep 27, 2005 at 02:41:25PM CEST:
>
> Note that even with this patch, you have an issue if the \r\n does not
> fit in the buffer.
Should be trivially fixed with this patch.
Cheers,
Ralf
--- orig/smtp.c 2005-09-27 14:24:32.000000000 +0200
+++ mutt/smtp.c 2005-09-27 19:14:00.000000000 +0200
@@ -144,6 +144,7 @@
progress_t progress;
struct stat st;
int r;
+ size_t buflen;
fp = fopen (msgfile, "r");
if (!fp)
@@ -168,8 +169,12 @@
return r;
}
- while (fgets (buf, sizeof (buf), fp))
+ while (fgets (buf, sizeof (buf) - 1, fp))
{
+ buflen = mutt_strlen (buf);
+ if (buflen && buf[buflen-1] == '\n'
+ && (buflen == 1 || buf[buflen - 2] != '\r'))
+ snprintf (buf + buflen - 1, sizeof (buf) - buflen + 1, "\r\n");
if (buf[0] == '.')
{
if (mutt_socket_write_d (conn, ".", 3) == -1)