From 68bc3df2cd980423b280fec11f2ed674beb6fb55 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Fri, 12 Jun 2020 17:41:40 -0400 Subject: 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. --- litterbox.c | 11 +---------- 1 file changed, 1 insertion(+), 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 }, -- cgit 1.4.1