From: Brandon Casey Date: Tue, 04 Aug 2009 21:40:57 GMT Subject: Re: [PATCH v2] Let mailsplit and mailinfo handle mails with CRLF line-endings Message-ID: <-WLgEY11_FJV7byR76pdKYY69wMV5WIIRr-HvzsgumvNMS0FNKTSfA@cipher.nrlssc.navy.mil> In-Reply-To: Brandon Casey wrote: > Be aware that if we use the version I suggested which pushes the '\r' back > into the input stream, I think we risk an infinite loop if size == 1. I don't > think that is possible from the current callers though. I think something like this would avoid any potential infinite loop, however improbable: if (c == '\n') { if (len > 1 && buf[len - 2] == '\r') buf[--len - 1] = '\n'; } else if (c == '\r') { c = getc(in); if (c == '\n') buf[len - 1] = '\n'; else if (c != EOF) ungetc(c, in); } -brandon