Skip to content

Commit

Permalink
Merge pull request #190 from vbscott/cfg_space
Browse files Browse the repository at this point in the history
Fixed bug with space before comment in config
  • Loading branch information
mbish authored Dec 20, 2021
2 parents b7562c8 + ac1a052 commit 77a88ec
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,15 @@ int ini_parse(FILE *file,
if (*prev_name && *start && start > line) {
/* Non-black line with leading whitespace, treat as continuation
of previous name's value (as per Python ConfigParser). */
if (!handler(user, section, prev_name, start) && !error) {
value = lskip(start);
/* Skip line if this line is a comment with whitespace infront */
if (*value == ';') {
continue;
}
if (!handler(user, section, prev_name, start) && !error) {
error = lineno;
break;
}
break;
}
}
else
#endif
Expand All @@ -102,7 +107,7 @@ int ini_parse(FILE *file,
else if (!error) {
/* No ']' found on section line */
error = lineno;
break;
break;
}
}
else if (*start && *start != ';') {
Expand All @@ -121,13 +126,13 @@ int ini_parse(FILE *file,
strncpy0(prev_name, name, sizeof(prev_name));
if (!handler(user, section, name, value) && !error) {
error = lineno;
break;
}
break;
}
}
else if (!error) {
/* No '=' found on name=value line */
error = lineno;
break;
break;
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions tests/confs/mockduo_extra_space.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[duo]
ikey = DIXYZV6YM8IFYVWBINCA
skey =
yWHSMhWucAcp7qvuH3HWTaSaKABs8Gaddiv1NIRo
host = localhost:4443
cafile = certs/mockduo-ca.pem
; This comment shouldn't break Duo
3 changes: 3 additions & 0 deletions tests/login_duo-4.t
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,6 @@ Test getting hostname
[4] Aborted Duo login for 'hostname': correct hostname
[1]

Test extra whitespace before comment in conf file
$ ${BUILDDIR}/login_duo/login_duo -d -c confs/mockduo_extra_space.conf -f preauth-allow true
[4] Skipped Duo login for 'preauth-allow': preauth-allowed
4 changes: 4 additions & 0 deletions tests/pam_duo-4.t
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,7 @@ Test max prompts equals PAM_MAXPROMPTS
Invalid passcode, please try again.
Autopushing login request to phone...
Invalid passcode, please try again.

Test extra whitespace before comment in conf fil
$ ./testpam.py -d -c confs/mockduo_extra_space.conf -f preauth-allow true
[4] Skipped Duo login for 'preauth-allow': preauth-allowed

0 comments on commit 77a88ec

Please sign in to comment.