about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-11-21 16:25:09 -0500
committerJune McEnroe <june@causal.agency>2019-11-21 16:25:09 -0500
commitcb38ad54eb54c1b3d3f0adbcf7b60eb50d6a3394 (patch)
tree865a155d6e94dc9c2d144387d24569fa84ef3a1f
parentUse a fixed buffer size for SASL PLAIN authentication (diff)
downloadpounce-cb38ad54eb54c1b3d3f0adbcf7b60eb50d6a3394.tar.gz
pounce-cb38ad54eb54c1b3d3f0adbcf7b60eb50d6a3394.zip
Use a static buffer for plainBase64
-rw-r--r--state.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/state.c b/state.c
index bbc3841..09156ff 100644
--- a/state.c
+++ b/state.c
@@ -37,7 +37,9 @@ static void require(const struct Message *msg, bool origin, size_t len) {
 	}
 }
 
-static char *plainBase64;
+// Maximum size of one AUTHENTICATE message.
+enum { AuthLen = 299 };
+static char plainBase64[BASE64_SIZE(AuthLen)];
 
 void stateLogin(
 	const char *pass, bool sasl, const char *plain,
@@ -48,9 +50,7 @@ void stateLogin(
 	if (sasl) {
 		serverFormat("CAP REQ :%s\r\n", capList(CapSASL));
 		if (plain) {
-			// Maxmimum size that fits in a single
-			// AUTHENTICATE message after base64 encoding.
-			byte buf[299];
+			byte buf[AuthLen];
 			size_t len = 1 + strlen(plain);
 			if (sizeof(buf) < len) {
 				errx(EX_SOFTWARE, "SASL PLAIN is too long");
@@ -59,8 +59,6 @@ void stateLogin(
 			for (size_t i = 0; plain[i]; ++i) {
 				buf[1 + i] = (plain[i] == ':' ? 0 : plain[i]);
 			}
-			plainBase64 = malloc(BASE64_SIZE(len));
-			if (!plainBase64) err(EX_OSERR, "malloc");
 			base64(plainBase64, buf, len);
 		}
 	}
@@ -80,7 +78,7 @@ static void handleCap(struct Message *msg) {
 		stateCaps |= caps;
 		if (caps & CapSASL) {
 			serverFormat(
-				"AUTHENTICATE %s\r\n", (plainBase64 ? "PLAIN" : "EXTERNAL")
+				"AUTHENTICATE %s\r\n", (plainBase64[0] ? "PLAIN" : "EXTERNAL")
 			);
 		}
 		if (!(stateCaps & CapSASL)) serverFormat("CAP END\r\n");
@@ -92,11 +90,9 @@ static void handleCap(struct Message *msg) {
 
 static void handleAuthenticate(struct Message *msg) {
 	(void)msg;
-	if (plainBase64) {
+	if (plainBase64[0]) {
 		serverFormat("AUTHENTICATE %s\r\n", plainBase64);
-		explicit_bzero(plainBase64, strlen(plainBase64));
-		free(plainBase64);
-		plainBase64 = NULL;
+		explicit_bzero(plainBase64, sizeof(plainBase64));
 	} else {
 		serverFormat("AUTHENTICATE +\r\n");
 	}
class='logsubject'>Add photos from September 29June McEnroe 2024-10-07Add photos from September 28June McEnroe 2024-10-07Add photos from September 22June McEnroe 2024-09-25Add photos from September 15June McEnroe 2024-09-24Add photos from September 14June McEnroe 2024-09-24Add photos from September 12June McEnroe 2024-09-24Add photos from September 7June McEnroe 2024-09-24Allow not having descriptionsJune McEnroe I'm sorry, I can't keep writing descriptions. It makes posting photos take too long, I often don't know the words for what I'm looking at, and a good description is an entirely different work of art than the photo I took, and I'm just a photographer. It's visual art. 2024-09-23Automatically select the last used lens for a bodyJune McEnroe 2024-09-19Add photos from September 5June McEnroe Had to prefix the folder number onto these file names manually because they must have come out of a different scanner or something. 2024-09-15Add some more film stocks to the listJune McEnroe 2024-09-13Add photos from September 2June McEnroe 2024-09-13Add Fomapan 200 to films listJune McEnroe 2024-09-10Add August 29 picnic photosJune McEnroe 2024-09-08Apply some bold to trips renderingJune McEnroe This seems easier to visually scan. The only other thing I'd like is a nicer date rendering but JavaScript is useless for that. 2024-09-08Render trips hopefully more efficientlyJune McEnroe 2024-09-08Allow removing bodies and lensesJune McEnroe 2024-09-08Limit body width so it looks less silly on desktopJune McEnroe 2024-09-07Handle no film being loadedJune McEnroe 2024-09-07Fancy up the text a littleJune McEnroe