summary refs log tree commit diff
path: root/state.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-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");
 	}
'2018-09-13 23:44:55 -0400'>2018-09-13Preview with nick in input windowJune McEnroe 2018-09-13Never send PRIVMSG to TagStatus or TagVerboseJune McEnroe 2018-09-13Move color selection to format.cJune McEnroe 2018-09-13Fix len for format->split at end of stringJune McEnroe 2018-09-13Avoid uninitialized x in uiReadJune McEnroe 2018-09-13Add IRCDefault to colors enumJune McEnroe 2018-09-13Return a format->split even at the end of the stringJune McEnroe 2018-09-13Fix weird tab-complete after commaJune McEnroe 2018-09-13Rewrite UI againJune McEnroe 2018-09-12Add note about C-oJune McEnroe 2018-09-12Use formatParse split to position input cursorJune McEnroe 2018-09-12Factor out IRC formatting parsingJune McEnroe 2018-09-11Add /help equivalent to /manJune McEnroe 2018-09-11Don't render every PM as a pingJune McEnroe 2018-09-11Add urlOpenMatchJune McEnroe 2018-09-10Depend on man.sh for chroot.tar targetJune McEnroe 2018-09-10Set LESSSECURE=1 in man.shJune McEnroe 2018-09-10Add /man commandJune McEnroe 2018-09-10Install man page in chrootJune McEnroe 2018-09-10Install man pageJune McEnroe 2018-09-10Split keys into subsections and document colorsJune McEnroe 2018-09-10Add "blank" lines to chatte.1June McEnroe 2018-09-10Document key bindings in chatte.1June McEnroe 2018-09-08Document slash commands in chatte.1June McEnroe