AmendHub

Download (as of this amendment):

jcs

/

subtext

/

amendments

/

629

fidopkt: Allocate an extra byte for the trailing terminator


jcs made amendment 629 13 days ago
--- fidopkt.c Sat Dec 6 21:04:31 2025 +++ fidopkt.c Fri Sep 18 20:12:00 2026 @@ -361,9 +361,9 @@ fidopkt_parse_message(char *packet_filename, struct fi msg_size, msg_size_limited); } - ret->body = xmalloc(msg_size_limited); + ret->body = xmalloc(msg_size_limited + 1); if (ret->body == NULL) { - logger_printf("[fidopkt] malloc(%lu) failed", msg_size_limited); + logger_printf("[fidopkt] malloc(%lu) failed", msg_size_limited + 1); goto parse_fail; } @@ -412,7 +412,7 @@ fidopkt_parse_message(char *packet_filename, struct fi continue; if (body_len == 0 && (line[0] == '\n' || line[0] == '\r')) continue; - if (llen + body_len > msg_size_limited) + if (body_len + llen + 1 > msg_size_limited) continue; if (line[llen - 1] == '\0') { memcpy(ret->body + body_len, line, llen - 1);