summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2016-01-04 16:14:19 +0000
committerschwarze <schwarze@openbsd.org>2016-01-04 16:14:19 +0000
commit0a4d8cf7a7c08b1f00a89b0802a9941ad9f6fce3 (patch)
tree45859db119ec8bbc5292c53db18e482c58a083b5
parentSkip "suspend" device node during probing (diff)
downloadwireguard-openbsd-0a4d8cf7a7c08b1f00a89b0802a9941ad9f6fce3.tar.xz
wireguard-openbsd-0a4d8cf7a7c08b1f00a89b0802a9941ad9f6fce3.zip
Bugfix: When errno happens to be EILSEQ upon entry to fgetws(3),
and when the file ends without a terminating Ln character, fgetws(3) discarded any characters read and reported bogus EOF. Never inspect errno(2) unless right after an error occurred! OK millert@
-rw-r--r--lib/libc/stdio/fgetws.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/libc/stdio/fgetws.c b/lib/libc/stdio/fgetws.c
index 0e66552ea45..d02ccd58cf7 100644
--- a/lib/libc/stdio/fgetws.c
+++ b/lib/libc/stdio/fgetws.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fgetws.c,v 1.7 2015/08/31 02:53:57 guenther Exp $ */
+/* $OpenBSD: fgetws.c,v 1.8 2016/01/04 16:14:19 schwarze Exp $ */
/* $NetBSD: fgetws.c,v 1.1 2003/03/07 07:11:37 tshiozak Exp $ */
/*-
@@ -52,9 +52,9 @@ fgetws(wchar_t * __restrict ws, int n, FILE * __restrict fp)
wsp = ws;
while (n-- > 1) {
- if ((wc = __fgetwc_unlock(fp)) == WEOF && errno == EILSEQ) {
+ if ((wc = __fgetwc_unlock(fp)) == WEOF &&
+ ferror(fp) && errno == EILSEQ)
goto error;
- }
if (wc == WEOF) {
if (wsp == ws) {
/* EOF/error, no characters read yet. */