summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2021-04-03 05:21:46 +0000
committerDamien Miller <djm@mindrot.org>2021-04-03 16:24:40 +1100
commitdc3c0be8208c488e64a8bcb7d9efad98514e0ffb (patch)
treeb29dedfa8c231dc2ffc444df07f0a6d42db3d694 /misc.c
parentf75bcbba58a08c670727ece5e3f8812125969799 (diff)
downloadopenssh-git-dc3c0be8208c488e64a8bcb7d9efad98514e0ffb.tar.gz
upstream: Fix two problems in string->argv conversion: 1) multiple
backslashes were not being dequoted correctly and 2) quoted space in the middle of a string was being incorrectly split. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A unit test for these cases has already been committed prompted by and based on GHPR#223 by Eero Häkkinen; ok markus@ OpenBSD-Commit-ID: d7ef27abb4eeeaf6e167e9312e4abe9e89faf1e4
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/misc.c b/misc.c
index d988ce3b..e2094544 100644
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.162 2021/02/28 01:50:47 dtucker Exp $ */
+/* $OpenBSD: misc.c,v 1.163 2021/04/03 05:21:46 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
* Copyright (c) 2005-2020 Damien Miller. All rights reserved.
@@ -1935,11 +1935,6 @@ argv_split(const char *s, int *argcp, char ***argvp)
/* Start of a token */
quote = 0;
- if (s[i] == '\\' &&
- (s[i + 1] == '\'' || s[i + 1] == '\"' || s[i + 1] == '\\'))
- i++;
- else if (s[i] == '\'' || s[i] == '"')
- quote = s[i++];
argv = xreallocarray(argv, (argc + 2), sizeof(*argv));
arg = argv[argc++] = xcalloc(1, strlen(s + i) + 1);
@@ -1959,8 +1954,10 @@ argv_split(const char *s, int *argcp, char ***argvp)
}
} else if (quote == 0 && (s[i] == ' ' || s[i] == '\t'))
break; /* done */
+ else if (quote == 0 && (s[i] == '\"' || s[i] == '\''))
+ quote = s[i]; /* quote start */
else if (quote != 0 && s[i] == quote)
- break; /* done */
+ quote = 0; /* quote end */
else
arg[j++] = s[i];
}