Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 18 Nov 2022 20:59:48 GMT
From:      Ed Maste <emaste@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 166551aa4da5 - stable/12 - dma: use canonical getline() loop
Message-ID:  <202211182059.2AIKxmHd043455@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=166551aa4da5705fa7d58c7aaefbcc472e5cdd03

commit 166551aa4da5705fa7d58c7aaefbcc472e5cdd03
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2022-02-03 18:51:06 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2022-11-18 20:57:45 +0000

    dma: use canonical getline() loop
    
    getline() returns -1 on erorr or EOF, so use that condition instead of
    feof() and check that there was no error after the loop exits.
    
    Reviewed by:    bapt, kevans (both earlier)
    MFC after:      3 weeks
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D34159
    
    (cherry picked from commit d21e71efce3963b068ccaa807a099b591dc220e9)
    (cherry picked from commit 2e8403e0215868a13e2bdd1c979fc351971b8d91)
---
 contrib/dma/mail.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/contrib/dma/mail.c b/contrib/dma/mail.c
index 9e00c22d71db..9641818b8814 100644
--- a/contrib/dma/mail.c
+++ b/contrib/dma/mail.c
@@ -405,10 +405,8 @@ readmail(struct queue *queue, int nodot, int recp_from_header)
 	if ((ssize_t)error < 0)
 		return (-1);
 
-	while (!feof(stdin)) {
+	while ((linelen = getline(&line, &linecap, stdin)) > 0) {
 		newline[0] = '\0';
-		if ((linelen = getline(&line, &linecap, stdin)) <= 0)
-			break;
 		if (had_last_line)
 			errlogx(EX_DATAERR, "bad mail input format:"
 				" from %s (uid %d) (envelope-from %s)",
@@ -510,8 +508,8 @@ readmail(struct queue *queue, int nodot, int recp_from_header)
 			}
 		}
 	}
-
-	ret = 0;
+	if (ferror(stdin) == 0)
+		ret = 0;
 fail:
 	free(line);
 	return (ret);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202211182059.2AIKxmHd043455>