Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190312203122.64157-1-AWilcox@Wilcox-Tech.com>
Date: Tue, 12 Mar 2019 15:31:22 -0500
From: "A. Wilcox" <AWilcox@...cox-Tech.com>
To: musl@...ts.openwall.com
Cc: "A. Wilcox" <AWilcox@...cox-Tech.com>
Subject: [PATCH] setvbuf: return failure if mode is invalid

POSIX requires setvbuf to return non-zero if `mode` is not one of _IONBF,
_IOLBF, or _IOFBF.
---
 src/stdio/setvbuf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/stdio/setvbuf.c b/src/stdio/setvbuf.c
index 06ea296c..523dddc8 100644
--- a/src/stdio/setvbuf.c
+++ b/src/stdio/setvbuf.c
@@ -12,13 +12,15 @@ int setvbuf(FILE *restrict f, char *restrict buf, int type, size_t size)
 
 	if (type == _IONBF) {
 		f->buf_size = 0;
-	} else {
+	} else if (type == _IOLBF || type == _IOFBF) {
 		if (buf && size >= UNGET) {
 			f->buf = (void *)(buf + UNGET);
 			f->buf_size = size - UNGET;
 		}
 		if (type == _IOLBF && f->buf_size)
 			f->lbf = '\n';
+	} else {
+		return -1;
 	}
 
 	f->flags |= F_SVB;
-- 
2.19.2

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.