aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub Jelen <jjelen@redhat.com>2020-04-14 18:32:07 +0200
committerJakub Jelen <jjelen@redhat.com>2020-04-20 14:14:33 +0200
commit1ba6ef689fe7f702d9921271dd422cae885de788 (patch)
tree18052255b244f62b091864cd3b9313ec8e0ffd8b /src
parentfecdc3cc0e6d051ebbe06414a15c6634a4126a8b (diff)
downloadlibssh-1ba6ef689fe7f702d9921271dd422cae885de788.tar.gz
libssh-1ba6ef689fe7f702d9921271dd422cae885de788.tar.xz
libssh-1ba6ef689fe7f702d9921271dd422cae885de788.zip
config_parser: Allow equal sign as a separator and eat up trailing whitespace
Probably fixes T210 Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/config_parser.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/config_parser.c b/src/config_parser.c
index 354ed35c..2f91d39f 100644
--- a/src/config_parser.c
+++ b/src/config_parser.c
@@ -76,7 +76,8 @@ out:
char *ssh_config_get_token(char **str)
{
register char *c;
- char *r;
+ bool had_equal = false;
+ char *r = NULL;
/* Ignore leading spaces */
for (c = *str; *c; c++) {
@@ -88,24 +89,36 @@ char *ssh_config_get_token(char **str)
/* If we start with quote, return the whole quoted block */
if (*c == '\"') {
for (r = ++c; *c; c++) {
- if (*c == '\"') {
+ if (*c == '\"' || *c == '\n') {
*c = '\0';
+ c++;
+ break;
+ }
+ /* XXX Unmatched quotes extend to the end of line */
+ }
+ } else {
+ /* Otherwise terminate on space, equal or newline */
+ for (r = c; *c; c++) {
+ if (*c == '\0') {
goto out;
+ } else if (isblank(*c) || *c == '=' || *c == '\n') {
+ had_equal = (*c == '=');
+ *c = '\0';
+ c++;
+ break;
}
}
}
- /* Otherwise terminate on space, equal or newline */
- for (r = c; *c; c++) {
- if (isblank(*c) || *c == '=' || *c == '\n') {
- *c = '\0';
- goto out;
+ /* Skip any other remaining whitespace */
+ while (isblank(*c) || *c == '\n' || (!had_equal && *c == '=')) {
+ if (*c == '=') {
+ had_equal = true;
}
+ c++;
}
-
out:
- *str = c + 1;
-
+ *str = c;
return r;
}