diff options
author | des <des@FreeBSD.org> | 2014-10-19 11:06:54 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2014-10-19 11:06:54 +0000 |
commit | 2cacd0032079549d14abc460dccc625aa1066394 (patch) | |
tree | 4c39d79732b80c01ed93330500cf7ec55cd98f7d /contrib/openpam | |
parent | 65ead9d18ac88bfe8360cecee582a9d3676f22ad (diff) | |
download | FreeBSD-src-2cacd0032079549d14abc460dccc625aa1066394.zip FreeBSD-src-2cacd0032079549d14abc460dccc625aa1066394.tar.gz |
Merge upstream r825: fix line continuation in whitespace
Diffstat (limited to 'contrib/openpam')
-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 5a4330c..b52e7df 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 { |