summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgilles <gilles@openbsd.org>2017-07-31 16:45:03 +0000
committergilles <gilles@openbsd.org>2017-07-31 16:45:03 +0000
commit40837cf207bef3e22bf48b1f7f8edd6abd991011 (patch)
tree4fd0bb9a3339a1a05d1c09fb826d8078cd9a224c
parentcmd_dump() is unused (diff)
downloadwireguard-openbsd-40837cf207bef3e22bf48b1f7f8edd6abd991011.tar.xz
wireguard-openbsd-40837cf207bef3e22bf48b1f7f8edd6abd991011.zip
handle empty output correctly in mda_getlastline()
diff from Casper Ti. Vector, ok eric@
-rw-r--r--usr.sbin/smtpd/mda.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/usr.sbin/smtpd/mda.c b/usr.sbin/smtpd/mda.c
index ef6b6f8ea8b..ead92a851c4 100644
--- a/usr.sbin/smtpd/mda.c
+++ b/usr.sbin/smtpd/mda.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mda.c,v 1.126 2016/11/30 17:43:32 eric Exp $ */
+/* $OpenBSD: mda.c,v 1.127 2017/07/31 16:45:03 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -617,7 +617,8 @@ mda_getlastline(int fd, char *dst, size_t dstsz)
char *ln = NULL;
size_t sz = 0;
ssize_t len;
-
+ int out = 0;
+
if (lseek(fd, 0, SEEK_SET) < 0) {
log_warn("warn: mda: lseek");
close(fd);
@@ -632,10 +633,11 @@ mda_getlastline(int fd, char *dst, size_t dstsz)
while ((len = getline(&ln, &sz, fp)) != -1) {
if (ln[len - 1] == '\n')
ln[len - 1] = '\0';
+ out = 1;
}
fclose(fp);
- if (sz != 0) {
+ if (out) {
(void)strlcpy(dst, "\"", dstsz);
(void)strnvis(dst + 1, ln, dstsz - 2, VIS_SAFE | VIS_CSTYLE);
(void)strlcat(dst, "\"", dstsz);