about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-09-09 12:44:01 -0400
committerJune McEnroe <june@causal.agency>2021-09-09 12:44:01 -0400
commit506c5ad906bc187c645cacea5080360fabd4abb4 (patch)
tree735d48c1ca40ce9bb31386036e94bd96b5e6acd8
parentMatch id names case-insensitively (diff)
downloadcatgirl-506c5ad906bc187c645cacea5080360fabd4abb4.tar.gz
catgirl-506c5ad906bc187c645cacea5080360fabd4abb4.zip
Correct handling of colons in SASL PLAIN
Only the first colon should be replaced with a null byte.

Ported from pounce.
Diffstat (limited to '')
-rw-r--r--handle.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/handle.c b/handle.c
index a8f054c..7b9835f 100644
--- a/handle.c
+++ b/handle.c
@@ -208,13 +208,13 @@ static void handleAuthenticate(struct Message *msg) {
 		return;
 	}
 
-	byte buf[299];
+	byte buf[299] = {0};
 	size_t len = 1 + strlen(self.plain);
-	if (sizeof(buf) < len) errx(EX_CONFIG, "SASL PLAIN is too long");
-	buf[0] = 0;
-	for (size_t i = 0; self.plain[i]; ++i) {
-		buf[1 + i] = (self.plain[i] == ':' ? 0 : self.plain[i]);
-	}
+	if (sizeof(buf) < len) errx(EX_USAGE, "SASL PLAIN is too long");
+	memcpy(&buf[1], self.plain, len - 1);
+	byte *sep = memchr(buf, ':', len);
+	if (!sep) errx(EX_USAGE, "SASL PLAIN missing colon");
+	*sep = 0;
 
 	char b64[BASE64_SIZE(sizeof(buf))];
 	base64(b64, buf, len);