From f8cc285a4a9f8f7ff5227de35aa52cde75c12cb9 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 17 Jan 2017 14:33:02 +0100 Subject: pdf: Convert non-printable keywords into PDF_TOK_ERROR. All known keywords are printable. Converting non-printable keywords into error tokens means we don't try to print garbage when showing error messages about unknown tokens. --- source/pdf/pdf-lex.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'source/pdf') diff --git a/source/pdf/pdf-lex.c b/source/pdf/pdf-lex.c index c7ba122b..34c753ab 100644 --- a/source/pdf/pdf-lex.c +++ b/source/pdf/pdf-lex.c @@ -35,6 +35,11 @@ static inline int iswhite(int ch) ch == '\040'; } +static inline int isprint(int ch) +{ + return ch >= ' ' && ch <= '~'; +} + static inline int unhex(int ch) { if (ch >= '0' && ch <= '9') return ch - '0'; @@ -439,8 +444,13 @@ pdf_token_from_keyword(char *key) case 'x': if (!strcmp(key, "xref")) return PDF_TOK_XREF; break; - default: - break; + } + + while (*key) + { + if (!isprint(*key)) + return PDF_TOK_ERROR; + ++key; } return PDF_TOK_KEYWORD; -- cgit v1.2.3