jcs
/subtext
/amendments
/471
fidopkt: Truncate tossed messages to ftn_max_tossed_message_size
jcs made amendment 471 about 1 year ago
--- fidopkt.c Fri Apr 7 14:56:15 2023
+++ fidopkt.c Sat Apr 8 23:10:29 2023
@@ -23,6 +23,7 @@
#include <time.h>
#include "fidopkt.h"
+#include "db.h"
#include "logger.h"
#include "util.h"
#include "zip.h" /* for GET_U* */
@@ -196,7 +197,7 @@ fidopkt_parse_message(char *packet_filename, struct fi
struct fidopkt_message *ret;
struct tm tm = { 0 };
struct fidopkt_address orig_address, dest_address;
- size_t body_len, len, llen, msg_size;
+ size_t body_len, len, llen, msg_size, msg_size_limited;
long tzoff = 0;
char dmon[6];
short dday, dyear, dhour, dmin, dsec, dutc, attr, n;
@@ -342,17 +343,25 @@ fidopkt_parse_message(char *packet_filename, struct fi
len -= msg_size;
- ret->body = xmalloc(msg_size);
+ msg_size_limited = msg_size;
+ if (db->config.ftn_max_tossed_message_size != 0 &&
+ msg_size > db->config.ftn_max_tossed_message_size) {
+ msg_size_limited = db->config.ftn_max_tossed_message_size;
+ logger_printf("[fidopkt] message size %ld > limit %ld, truncating",
+ msg_size, msg_size_limited);
+ }
+
+ ret->body = xmalloc(msg_size_limited);
if (ret->body == NULL) {
- logger_printf("[fidopkt] malloc(%lu) failed", msg_size);
+ logger_printf("[fidopkt] malloc(%lu) failed", msg_size_limited);
goto parse_fail;
}
body_len = 0;
tear = false;
while (msg_size) {
- llen = fidopkt_read_until(&buf, &msg_size, '\r', sizeof(line), line,
- false);
+ llen = fidopkt_read_until(&buf, &msg_size, '\r', sizeof(line),
+ line, false);
if (body_len == 0 && strncmp(line, "AREA:", 5) == 0) {
line[llen] = '\0';
@@ -392,6 +401,8 @@ fidopkt_parse_message(char *packet_filename, struct fi
if (line[0] == ' ' && line[1] == ' ')
continue;
if (body_len == 0 && (line[0] == '\n' || line[0] == '\r'))
+ continue;
+ if (llen + body_len > msg_size_limited)
continue;
if (line[llen - 1] == '\0') {
memcpy(ret->body + body_len, line, llen - 1);