aboutsummaryrefslogtreecommitdiff
path: root/lib/libpam
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2014-10-18 22:49:18 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2014-10-18 22:49:18 +0000
commitd2afd010d41e1acf0fe4e164246c8055368bf503 (patch)
treef0fd8e3519226997abf7a053767b96727e7e95cc /lib/libpam
parentadf180b55c9bdbf02c7daf6a62bdecd3b7dd6cd6 (diff)
downloadsrc-d2afd010d41e1acf0fe4e164246c8055368bf503.tar.gz
src-d2afd010d41e1acf0fe4e164246c8055368bf503.zip
Merge upstream r825: fix line continuation in whitespace
Notes
Notes: svn path=/vendor/openpam/dist/; revision=273269
Diffstat (limited to 'lib/libpam')
-rw-r--r--lib/libpam/openpam_readword.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/lib/libpam/openpam_readword.c b/lib/libpam/openpam_readword.c
index 5a4330c6c75d..b52e7dfa41c0 100644
--- a/lib/libpam/openpam_readword.c
+++ b/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 {