Commit Diff


commit - 9bf09c65bfe309eefd6c75a955fd732a67357c53
commit + 44703d29ff87d414604a05fc14a5621d34ba1c39
blob - c0c86958906a25cd5abb65d1a295de2cc7abcbea
blob + a5f580c44536a6a92993a9db1baf2d6493695f83
--- totp.c
+++ totp.c
@@ -98,17 +98,20 @@ b32decode(const char *s, char *q, size_t qlen)
 static int
 uri2secret(char *s)
 {
-	char		*q, *t;
+	char		*q, *t, *f, *secret = NULL;
 
 	if ((q = strchr(s, '?')) == NULL)
 		return (-1);
-	if ((t = strstr(q, "?secret=")) == NULL &&
-	    (t = strstr(q, "&secret=")) == NULL)
+
+	t = q + 1;
+	while ((f = strsep(&t, "&")) != NULL) {
+		if (!strncmp(f, "secret=", 7))
+			secret = f + 7;
+	}
+
+	if (secret == NULL)
 		return (-1);
-	t += 8;
-	while (*t != '\0' && *t != '&' && *t != '#')
-		*s++ = *t++;
-	*s = '\0';
+	memmove(s, secret, strlen(secret) + 1);
 	return (0);
 }