From f9e45b9d34a7ed8d2947b6ba3e0ba8f4dd8a5e0b Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Wed, 19 May 2021 16:41:26 -0400 Subject: Fix MOTD buffer reallocation Woops. Not how that should be done. --- litterbox.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/litterbox.c b/litterbox.c index a7c0e30..48e5b60 100644 --- a/litterbox.c +++ b/litterbox.c @@ -217,8 +217,10 @@ static void handleReplyMOTD(struct Message *msg) { 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 = (motd.cap ? motd.cap * 2 : len + 1); + size_t req = motd.len + len + 1; + if (req > motd.cap) { + if (!motd.cap) motd.cap = 1024; + while (req > motd.cap) motd.cap *= 2; motd.buf = realloc(motd.buf, motd.cap); if (!motd.buf) err(EX_OSERR, "realloc"); } -- cgit 1.4.1