Skip to content
Snippets Groups Projects
Commit 4f11e1df authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Better detection of correctly-null-terminated body text

CID 229603 
parent 77b90b5f
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #2825 passed
......@@ -85,7 +85,7 @@ int msgdump(FILE* fp, const char* fname)
if(hdr.subj[sizeof(hdr.subj)-1] != 0)
fprintf(stderr,"%s Unterminated 'subj' field\n", fname);
if(hdr.time[sizeof(hdr.time)-1] != 0)
fprintf(stderr,"%s Untermianted 'time' field\n", fname);
fprintf(stderr,"%s Unterminated 'time' field\n", fname);
printf("Subj: %.*s\n", (int)sizeof(hdr.subj)-1, hdr.subj);
......@@ -103,16 +103,17 @@ int msgdump(FILE* fp, const char* fname)
return(__COUNTER__);
}
char* body = calloc((end - sizeof(hdr)) + 1, 1);
long len = end - sizeof(hdr);
char* body = calloc(len + 1, 1);
if(body == NULL) {
fprintf(stderr, "!MALLOC failure\n");
return __COUNTER__;
}
fseek(fp, sizeof(hdr), SEEK_SET);
fread(body, end - sizeof(hdr), 1, fp);
fread(body, len, 1, fp);
fprintf(bodyfp, "\n-start of message text-\n");
char* p = body;
while(*p) {
while(*p && p < body + len) {
if((p == body || *(p - 1) == '\r') && *p == 1) {
fputc('@', ctrlfp);
p++;
......@@ -132,7 +133,10 @@ int msgdump(FILE* fp, const char* fname)
fputc('\n', bodyfp);
}
}
fprintf(bodyfp, "-end of message text-\n");
if(p == (body + len) - 1)
fprintf(bodyfp, "-end of message text-\n");
else
fprintf(bodyfp, "-PREMATURE end of message text-\n");
free(body);
printf("\n");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment