From 7a702103b4490e370b36587c34b8b549a75ef3a5 Mon Sep 17 00:00:00 2001 From: Chris Liddell <chris.liddell@artifex.com> Date: Tue, 28 Aug 2018 14:17:09 +0100 Subject: Bug 699678: don't allow bytes to be "unread" from stdin --- base/stream.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/base/stream.c b/base/stream.c index 815935827..68e119fd7 100644 --- a/base/stream.c +++ b/base/stream.c @@ -499,7 +499,11 @@ spputc(register stream * s, byte b) int sungetc(register stream * s, byte c) { - if (!s_is_reading(s) || s->srptr < s->cbuf || *(s->srptr) != c) + /* cbuf == NULL means this stream is stdin, and we shouldn't + unread from stdin, ever. + */ + if (s->cbuf == NULL || !s_is_reading(s) || + s->srptr < s->cbuf || *(s->srptr) != c) return ERRC; s->srptr--; return 0; -- cgit v1.2.3