Commit 96d27072 authored by rswindell's avatar rswindell
Browse files

If a pkdmsg type is not 0x0002, then just move forward 2-bytes until there is

valid pkdmsg type.
This will allow better re-sync with a badly corrupted packet.
I waffled about whether it should try to read the variable header fields if the
DateTime field of the fixed header is invalid. Currently, it does. The pkdmsg
header does not have very good identifying marks to re-sync with, so it's
still possible that a valid msg that follows a corrupted one could get skipped.
I would need some good set of varying examples of corrupted packets to test
with, but I'm sure it's possible to "do better".
parent 29337296
......@@ -131,25 +131,46 @@ int pktdump(FILE* fp, const char* fname, FILE* out)
offset=ftell(fp);
if(fread(&pkdmsg.type, 1, sizeof(pkdmsg.type), fp) != sizeof(pkdmsg.type))
break;
if(pkdmsg.type == FIDO_PACKET_TERMINATOR)
continue;
if(pkdmsg.type != 2) {
printf("%s %06lX Corrupted Message Header (type: %04hX)\n"
,fname
,offset
,pkdmsg.type);
continue;
}
bool corrupted = false;
fseek(fp, offset, SEEK_SET);
/* Read fixed-length header fields (or final NULL byte) */
if(fread(&pkdmsg,sizeof(BYTE),sizeof(pkdmsg),fp)!=sizeof(pkdmsg))
break;
if(pkdmsg.time[0] == '\0' || pkdmsg.time[sizeof(pkdmsg.time) - 1] != '\0') {
printf("%s %06lX Corrupted Message Header (DateTime)\n"
,fname
,offset);
corrupted = true;
}
/* Read variable-length header fields */
freadstr(fp,to,sizeof(to));
freadstr(fp,from,sizeof(from));
freadstr(fp,subj,sizeof(subj));
if(pkdmsg.type != 2
if(!corrupted && (from[0] == '\0'
|| to[sizeof(to) - 1] != '\0'
|| from[sizeof(from) - 1] != '\0'
|| subj[sizeof(subj) - 1] != '\0'
|| from[0] == '\0'
|| pkdmsg.time[0] == '\0'
|| pkdmsg.time[sizeof(pkdmsg.time) - 1] != '\0'
) {
printf("%s %06lX Corrupted Message Header\n"
)) {
printf("%s %06lX Corrupted Message Header (variable portion)\n"
,fname
,offset);
corrupted = true;
}
if(corrupted) { // Seek to the end of the message body (hopefully)
while((ch = fgetc(fp)) != EOF && ch != 0)
;
continue;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment