From 17db43b5841504b694203952fb0e82246c06a97f Mon Sep 17 00:00:00 2001 From: Herbert Xu Date: Mon, 5 Jan 2015 22:50:57 +1100 Subject: input: Allow two consecutive calls to pungetc The commit ef91d3d6a4c39421fd3a391e02cd82f9f3aee4a8 ([PARSER] Handle backslash newlines properly after dollar sign) created cases where we make two consecutive calls to pungetc. As we don't explicitly support that there are corner cases where you end up with garbage input leading to undefined behaviour. This patch adds explicit support for two consecutive calls to pungetc. Reported-by: Jilles Tjoelker Reported-by: Juergen Daubert Signed-off-by: Herbert Xu --- src/input.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/input.h') diff --git a/src/input.h b/src/input.h index ad8b463..ec97c1d 100644 --- a/src/input.h +++ b/src/input.h @@ -49,6 +49,12 @@ struct strpush { int prevnleft; struct alias *ap; /* if push was associated with an alias */ char *string; /* remember the string since it may change */ + + /* Remember last two characters for pungetc. */ + int lastc[2]; + + /* Number of outstanding calls to pungetc. */ + int unget; }; /* @@ -66,6 +72,12 @@ struct parsefile { char *buf; /* input buffer */ struct strpush *strpush; /* for pushing strings at this level */ struct strpush basestrpush; /* so pushing one is fast */ + + /* Remember last two characters for pungetc. */ + int lastc[2]; + + /* Number of outstanding calls to pungetc. */ + int unget; }; extern struct parsefile *parsefile; -- cgit 1.4.1