summaryrefslogtreecommitdiffstats
path: root/authfile.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2019-09-03 08:30:47 +0000
committerDamien Miller <djm@mindrot.org>2019-09-03 18:39:31 +1000
commitdd8002fbe63d903ffea5be7b7f5fc2714acab4a0 (patch)
treeac6cf10455cbf734c7d257288ab265e6113f2e42 /authfile.c
parentc72d78ccbe642e08591a626e5de18381489716e0 (diff)
upstream: move advance_past_options to authfile.c and make it
public; ok markus@ OpenBSD-Commit-ID: edda2fbba2c5b1f48e60f857a2010479e80c5f3c
Diffstat (limited to 'authfile.c')
-rw-r--r--authfile.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/authfile.c b/authfile.c
index 5e335ce4..37341189 100644
--- a/authfile.c
+++ b/authfile.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: authfile.c,v 1.134 2019/08/05 11:50:33 dtucker Exp $ */
+/* $OpenBSD: authfile.c,v 1.135 2019/09/03 08:30:47 djm Exp $ */
/*
* Copyright (c) 2000, 2013 Markus Friedl. All rights reserved.
*
@@ -528,3 +528,25 @@ sshkey_check_revoked(struct sshkey *key, const char *revoked_keys_file)
}
}
+/*
+ * Advanced *cpp past the end of key options, defined as the first unquoted
+ * whitespace character. Returns 0 on success or -1 on failure (e.g.
+ * unterminated quotes).
+ */
+int
+sshkey_advance_past_options(char **cpp)
+{
+ char *cp = *cpp;
+ int quoted = 0;
+
+ for (; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) {
+ if (*cp == '\\' && cp[1] == '"')
+ cp++; /* Skip both */
+ else if (*cp == '"')
+ quoted = !quoted;
+ }
+ *cpp = cp;
+ /* return failure for unterminated quotes */
+ return (*cp == '\0' && quoted) ? -1 : 0;
+}
+