From 1b7c84abfae9f45e7f0c0d8d95b588407c1fd239 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 17 May 2022 19:03:11 +0100 Subject: [PATCH] Temporarily added some debugs and an assert() statement to show where the message buffer is getting truncated during large reads on low memory systems. --- citadel/modules/ctdlproto/serv_messages.c | 7 +++---- citadel/msgbase.c | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/citadel/modules/ctdlproto/serv_messages.c b/citadel/modules/ctdlproto/serv_messages.c index 3d37dcc81..f48060b14 100644 --- a/citadel/modules/ctdlproto/serv_messages.c +++ b/citadel/modules/ctdlproto/serv_messages.c @@ -602,7 +602,8 @@ void cmd_ent0(char *entargs) { /* Read in the message from the client. */ if (do_confirm) { cprintf("%d send message\n", START_CHAT_MODE); - } else { + } + else { cprintf("%d send message\n", SEND_LISTING); } @@ -612,9 +613,7 @@ void cmd_ent0(char *entargs) { ((!IsEmptyStr(supplied_euid)) ? supplied_euid : NULL), NULL, references); - /* Put together one big recipients struct containing to/cc/bcc all in - * one. This is for the envelope. - */ + // Put together one big recipients struct containing to/cc/bcc all in one. This is for the envelope. char *all_recps = malloc(SIZ * 3); strcpy(all_recps, recp); if (!IsEmptyStr(cc)) { diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 3acd13b36..17e58e261 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include "ctdl_module.h" #include "citserver.h" @@ -2968,18 +2969,18 @@ long quickie_message(const char *from, /* * Back end function used by CtdlMakeMessage() and similar functions */ -StrBuf *CtdlReadMessageBodyBuf(char *terminator, /* token signalling EOT */ +StrBuf *CtdlReadMessageBodyBuf(char *terminator, // token signalling EOT long tlen, - size_t maxlen, /* maximum message length */ - StrBuf *exist, /* if non-null, append to it; - exist is ALWAYS freed */ - int crlf /* CRLF newlines instead of LF */ + size_t maxlen, // maximum message length + StrBuf *exist, // if non-null, append to it; exist is ALWAYS freed + int crlf // CRLF newlines instead of LF ) { StrBuf *Message; StrBuf *LineBuf; int flushing = 0; int finished = 0; int dotdot = 0; + int lines_read = 0; // FIXME remove this after debugging LineBuf = NewStrBufPlain(NULL, SIZ); if (exist == NULL) { @@ -2999,6 +3000,7 @@ StrBuf *CtdlReadMessageBodyBuf(char *terminator, /* token signalling EOT */ if (CtdlClientGetLine(LineBuf) < 0) { finished = 1; } + ++lines_read; if ((StrLength(LineBuf) == tlen) && (!strcmp(ChrPtr(LineBuf), terminator))) { finished = 1; } @@ -3022,6 +3024,14 @@ StrBuf *CtdlReadMessageBodyBuf(char *terminator, /* token signalling EOT */ } while (!finished); FreeStrBuf(&LineBuf); + + // DEBUG remove this + int lines_in_buffer = num_tokens(ChrPtr(Message), '\n'); + syslog(LOG_DEBUG, "\033[31mLines from client : %d\033[0m", lines_read); + syslog(LOG_DEBUG, "\033[32mLines in buffer : %d\033[0m", lines_in_buffer); + assert(lines_read == lines_in_buffer); + + return Message; } -- 2.30.2