jcs
/subtext
/amendments
/638
fidopkt: Fix some off-by-ones
jcs made amendment 638 1 day ago
--- fidopkt.c Fri Sep 18 20:12:00 2026
+++ fidopkt.c Tue Sep 22 13:51:45 2026
@@ -105,8 +105,12 @@ fidopkt_read_until(char **buf, size_t *buf_len, char d
break;
}
}
- if (terminate || found)
- ret[retpos - 1] = '\0';
+ if (terminate || found) {
+ if (retpos == 0)
+ ret[0] = '\0';
+ else
+ ret[retpos - 1] = '\0';
+ }
return retpos;
}
@@ -283,7 +287,7 @@ fidopkt_parse_message(char *packet_filename, struct fi
if (ret == NULL) {
logger_printf("[fidopkt] malloc(%lu) failed",
sizeof(struct fidopkt_message));
- goto parse_fail;
+ return NULL;
}
if (header == NULL) {
@@ -370,7 +374,7 @@ fidopkt_parse_message(char *packet_filename, struct fi
body_len = 0;
tear = false;
while (msg_size) {
- llen = fidopkt_read_until(&buf, &msg_size, '\r', sizeof(line),
+ llen = fidopkt_read_until(&buf, &msg_size, '\r', sizeof(line) - 1,
line, false);
if (body_len == 0 && strncmp(line, "AREA:", 5) == 0) {