summary refs log tree commit diff
path: root/litterbox.c
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 /litterbox.c
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.
Diffstat (limited to '')
-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 },
. Wake-on-LAN is funny. 2017-08-04Use $() in install.shJune McEnroe Something gave me the impression that sh did not like this, but it's specified by POSIX. 2017-08-02Create Code Tarmak 3 layoutJune McEnroe 2017-07-31Add tupJune McEnroe 2017-07-31Use designated initializer for hnel tableJune McEnroe I did not know this syntax worked! 2017-07-30Add juneJune McEnroe 2017-07-30Play nethack as ValkyrieJune McEnroe 2017-07-28Add toggle to hnelJune McEnroe 2017-07-28Install slJune McEnroe 2017-07-25Add up, supJune McEnroe 2017-07-24Autopickup ringsJune McEnroe 2017-07-24Name dogJune McEnroe 2017-07-23Add nethackrcJune McEnroe 2017-07-23Remove useless setuid in briJune McEnroe Don't you think it would be better if the setuid bit only gave you permission to do it and didn't do it for you? 2017-07-23Clean up hnel a tiny bitJune McEnroe 2017-07-21Set window size in hnelJune McEnroe 2017-07-21Add hnelJune McEnroe 2017-07-19chmod 600 in dtchJune McEnroe