summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-06-12 17:41:40 -0400
committerJune McEnroe <june@causal.agency>2020-06-12 17:41:40 -0400
commit68bc3df2cd980423b280fec11f2ed674beb6fb55 (patch)
tree2f4fc38d3b4df4ea961c39ac2ba65e0e2a460b9b
parentAdd additional permission for linking with LibreSSL (diff)
downloadlitterbox-68bc3df2cd980423b280fec11f2ed674beb6fb55.tar.gz
litterbox-68bc3df2cd980423b280fec11f2ed674beb6fb55.zip
Remove RPL_MOTDSTART handler
Relying on the MOTDSTART handler to set motd.cap and allocate the buffer
is an issue if a regular RPL_MOTD is received without one. Just allocate
the buffer on the first RPL_MOTD.
-rw-r--r--litterbox.c11
1 files changed, 1 insertions, 10 deletions
diff --git a/litterbox.c b/litterbox.c
index bb98b3e..0fe8797 100644
--- a/litterbox.c
+++ b/litterbox.c
@@ -213,21 +213,13 @@ static struct {
 	size_t cap, len;
 } motd;
 
-static void handleReplyMOTDStart(struct Message *msg) {
-	(void)msg;
-	motd.len = 0;
-	motd.cap = 80;
-	motd.buf = malloc(motd.cap);
-	if (!motd.buf) err(EX_OSERR, "malloc");
-}
-
 static void handleReplyMOTD(struct Message *msg) {
 	require(msg, false, 2);
 	char *line = msg->params[1];
 	if (!strncmp(line, "- ", 2)) line += 2;
 	size_t len = strlen(line);
 	if (motd.len + len + 1 > motd.cap) {
-		motd.cap *= 2;
+		motd.cap = (motd.cap ? motd.cap * 2 : len + 1);
 		motd.buf = realloc(motd.buf, motd.cap);
 		if (!motd.buf) err(EX_OSERR, "realloc");
 	}
@@ -674,7 +666,6 @@ static const struct Handler {
 	{ "332", true, handleReplyTopic },
 	{ "353", true, handleReplyNames },
 	{ "372", false, handleReplyMOTD },
-	{ "375", false, handleReplyMOTDStart },
 	{ "376", true, handleReplyEndOfMOTD },
 	{ "900", false, handleReplyLoggedIn },
 	{ "904", false, handleErrorSASLFail },