From 4632c71d8f883fa5a4b208673b1b36e83e3e8c41 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 9 Dec 2015 21:51:45 -0800 Subject: Bugfix: crash in get_line. Incorrect, irrelevant handle test inside stdio_get_line virtual function fails to detect closed stream, leading to a null pointer passed to the stdio library. * stream.c (snarf_line): Rewrite according to pattern followed by the other functions. We must test h->f for null, not stream->co.handle, which never goes null until the object is being reclaimed by gc. --- stream.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/stream.c b/stream.c index fd170bc0..a1a41036 100644 --- a/stream.c +++ b/stream.c @@ -584,16 +584,14 @@ static wchar_t *snarf_line(struct stdio_handle *h) static val stdio_get_line(val stream) { - errno = 0; - if (stream->co.handle == 0) { - return stdio_maybe_read_error(stream); - } else { - struct stdio_handle *h = coerce(struct stdio_handle *, stream->co.handle); + struct stdio_handle *h = coerce(struct stdio_handle *, stream->co.handle); + if (h->f) { wchar_t *line = snarf_line(h); - if (!line) - return stdio_maybe_read_error(stream); - return string_own(line); + if (line) + return string_own(line); } + + return stdio_maybe_read_error(stream); } static val stdio_get_char(val stream) -- cgit v1.2.3