Browse Source

fix uidvalidity recovery with really long message-id headers

re-using the file name buffer for the headers wasn't such a great idea,
as _POSIX_PATH_MAX is only 256, while RFC2822 permits lines up to 1000
chars. and sure enough, i have a message with a whopping 470-char
message-id header ...
wip/unchecked-remove
Oswald Buddenhagen 7 years ago
parent
commit
5072032939
  1. 21
      src/drv_maildir.c

21
src/drv_maildir.c

@ -1153,28 +1153,29 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist )
goto retry; goto retry;
} }
int off, in_msgid = 0; int off, in_msgid = 0;
while ((want_tuid || want_msgid) && fgets( nbuf, sizeof(nbuf), f )) { char lnbuf[1000]; // Says RFC2822
int bufl = strlen( nbuf ); while ((want_tuid || want_msgid) && fgets( lnbuf, sizeof(lnbuf), f )) {
if (bufl && nbuf[bufl - 1] == '\n') int bufl = strlen( lnbuf );
if (bufl && lnbuf[bufl - 1] == '\n')
--bufl; --bufl;
if (bufl && nbuf[bufl - 1] == '\r') if (bufl && lnbuf[bufl - 1] == '\r')
--bufl; --bufl;
if (!bufl) if (!bufl)
break; break;
if (want_tuid && starts_with( nbuf, bufl, "X-TUID: ", 8 )) { if (want_tuid && starts_with( lnbuf, bufl, "X-TUID: ", 8 )) {
if (bufl < 8 + TUIDL) { if (bufl < 8 + TUIDL) {
error( "Maildir error: malformed X-TUID header (UID %u)\n", uid ); error( "Maildir error: malformed X-TUID header (UID %u)\n", uid );
continue; continue;
} }
memcpy( entry->tuid, nbuf + 8, TUIDL ); memcpy( entry->tuid, lnbuf + 8, TUIDL );
want_tuid = 0; want_tuid = 0;
in_msgid = 0; in_msgid = 0;
continue; continue;
} }
if (want_msgid && starts_with_upper( nbuf, bufl, "MESSAGE-ID:", 11 )) { if (want_msgid && starts_with_upper( lnbuf, bufl, "MESSAGE-ID:", 11 )) {
off = 11; off = 11;
} else if (in_msgid) { } else if (in_msgid) {
if (!isspace( nbuf[0] )) { if (!isspace( lnbuf[0] )) {
in_msgid = 0; in_msgid = 0;
continue; continue;
} }
@ -1182,13 +1183,13 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist )
} else { } else {
continue; continue;
} }
while (off < bufl && isspace( nbuf[off] )) while (off < bufl && isspace( lnbuf[off] ))
off++; off++;
if (off == bufl) { if (off == bufl) {
in_msgid = 1; in_msgid = 1;
continue; continue;
} }
entry->msgid = nfstrndup( nbuf + off, bufl - off ); entry->msgid = nfstrndup( lnbuf + off, bufl - off );
want_msgid = 0; want_msgid = 0;
in_msgid = 0; in_msgid = 0;
} }

Loading…
Cancel
Save