about summary refs log tree commit diff
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");
 	}
2014-12-23git: update to v2.2.1Christian Hesse 2014-12-13filter: fix libravatar email-filter https issueChristian Hesse 2014-12-13ui-diff: add "stat only" diff typeJohn Keeping 2014-12-13Change "ss" diff flag to an enumJohn Keeping 2014-12-13ui-shared: remove toggle_ssdiff arg to cgit_diff_link()John Keeping 2014-12-13ui-shared: remove toggle_ssdiff arg to cgit_commit_link()John Keeping 2014-08-07git: update to v2.0.4John Keeping 2014-08-07Always check if README exists in choose_readme()Lukas Fleischer 2014-08-01cgitrc.5: we mean a cgi response, not requestJason A. Donenfeld 2014-07-28ui-stats.c: set parent pointer to NULL after freeing itJohn Keeping 2014-07-28git: update to v2.0.3John Keeping 2014-07-28parsing.c: make commit buffer constJohn Keeping 2014-06-30Bump version.Jason A. Donenfeld 2014-06-29remove debug fprinf() calls that sneaked in with commit 79c985Christian Hesse 2014-06-28git: update to 2.0.1Christian Hesse 2014-06-28ui-patch: Flush stdout after outputting dataJohn Keeping 2014-06-28ui-log: ignore unhandled argumentsJohn Keeping 2014-06-28git: update for git 2.0Christian Hesse 2014-04-17remove trailing whitespaces from source filesChristian Hesse 2014-04-12git: update to 1.9.2Christian Hesse 2014-04-05Fix cgit_parse_url when a repo url is contained in another repo urlJulian Maurice 2014-03-20Makefile: use more reliable git tarball mirrorJason A. Donenfeld 2014-03-20git: update to 1.9.1Christian Hesse