diff options
author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2014-10-19 11:06:54 +0000 |
---|---|---|
committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2014-10-19 11:06:54 +0000 |
commit | 49e2762fba099fff8a17e7f8604d1293c8449052 (patch) | |
tree | 4c39d79732b80c01ed93330500cf7ec55cd98f7d /contrib/openpam/lib | |
parent | 020b8f17a092a1bca30f3ac6627ee98f0fffbc88 (diff) | |
parent | d2afd010d41e1acf0fe4e164246c8055368bf503 (diff) |
Merge upstream r825: fix line continuation in whitespace
Notes
Notes:
svn path=/head/; revision=273273
Diffstat (limited to 'contrib/openpam/lib')
-rw-r--r-- | contrib/openpam/lib/libpam/openpam_readword.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/contrib/openpam/lib/libpam/openpam_readword.c b/contrib/openpam/lib/libpam/openpam_readword.c index 5a4330c6c75d..b52e7dfa41c0 100644 --- a/contrib/openpam/lib/libpam/openpam_readword.c +++ b/contrib/openpam/lib/libpam/openpam_readword.c @@ -55,18 +55,35 @@ openpam_readword(FILE *f, int *lineno, size_t *lenp) { char *word; size_t size, len; - int ch, comment, escape, quote; + int ch, escape, quote; int serrno; errno = 0; /* skip initial whitespace */ - comment = 0; - while ((ch = getc(f)) != EOF && ch != '\n') { - if (ch == '#') - comment = 1; - if (!is_lws(ch) && !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 { |