From e58f05403e18a2505da2fb78dc7cf43767a3fc21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Mon, 17 Mar 2014 14:11:41 +0000 Subject: [PATCH] Support line continuation in whitespace. git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@792 185d5e19-27fe-0310-9dcf-9bff6b9f3609 --- lib/libpam/openpam_readword.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/libpam/openpam_readword.c b/lib/libpam/openpam_readword.c index 5fba5bc..ae10527 100644 --- a/lib/libpam/openpam_readword.c +++ b/lib/libpam/openpam_readword.c @@ -61,12 +61,29 @@ openpam_readword(FILE *f, int *lineno, size_t *lenp) errno = 0; /* skip initial whitespace */ - comment = 0; - while ((ch = getc(f)) != EOF && ch != '\n') { - if (ch == '#') - comment = 1; - if (!is_lws(ch) && !comment) + comment = escape = quote = 0; + while ((ch = getc(f)) != EOF) { + if (ch == '\n') { + /* either EOL or line continuation */ + if (!escape) + break; + if (lineno != NULL) + ++*lineno; + escape = 0; + } else if (escape) { + /* escaped something else */ break; + } else if (ch == '#') { + /* comment: until EOL, no continuation */ + while ((ch = getc(f)) != EOF) + if (ch == '\n') + break; + break; + } else if (ch == '\\') { + escape = 1; + } else if (!is_ws(ch)) { + break; + } } if (ch == EOF) return (NULL); @@ -76,7 +93,6 @@ openpam_readword(FILE *f, int *lineno, size_t *lenp) word = NULL; size = len = 0; - escape = quote = 0; while ((ch = fgetc(f)) != EOF && (!is_ws(ch) || quote || escape)) { if (ch == '\\' && !escape && quote != '\'') { /* escape next character */ @@ -90,7 +106,7 @@ openpam_readword(FILE *f, int *lineno, size_t *lenp) } else if (ch == quote && !escape) { /* end quote */ quote = 0; - } else if (ch == '\n' && escape && quote != '\'') { + } else if (ch == '\n' && escape) { /* line continuation */ escape = 0; } else {