diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2016-01-04 16:14:20 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2016-01-04 16:14:20 +0000 |
commit | b328be7dcf2e4b80432edd8c7760d4229dea73f9 (patch) | |
tree | 65ad5a3fe2bc6fb7db2ce6403532c30d348ebd48 /lib/libc | |
parent | 940aa6d13b8e0d8191fc629a1e24b3a67a64c9a6 (diff) |
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@
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/stdio/fgetws.c | 6 |
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. */ |