On Fri, 12 Nov 2010 20:45:17 +1100, Rod Whitworth wrote > On Fri, 12 Nov 2010 11:21:42 +0200, Alexey Suslikov wrote: > >> Are there any better POP3 servers with APOP support? > > > >mail/dovecot ? > > > Or Teapop?
Thank you for your suggestions, I'll give them a try. For the moment, I "fixed" the issue by the attached patch allocating aligned memory for mbuf. Kind of ugly because of all the additional free-s. Besides there are more instances of md5_process_bytes where it is not apparent if the argument is aligned. IMO the issue should rather be fixed in md5.c but I have no idea how. Regards, Michael --- src/mailbox.c.orig Sat Nov 13 13:44:15 2010 +++ src/mailbox.c Sat Nov 13 13:50:37 2010 @@ -334,10 +334,11 @@ } #endif +#define MBUF_SIZE 128 int mb_parse(int compare) { ssize_t tmp2; - char mbuf[128]; + char *mbuf; ssize_t mcount; off_t act_ofs = 0; char msgdate[21]; @@ -349,10 +350,17 @@ size_t tmpfrom_size = 0, tmpsize = 0, tmpcrlfsize = 0; char tmpdigest[16]; int newline = 1, header, fixed; + + if (posix_memalign((void**)&mbuf, 16, MBUF_SIZE) != 0) { + pop_log(pop_priority, "mailbox: posix_memalign"); + send_error("Could not allocate alligned memory."); + exit(1); + } if (compare) if (lseek(mailboxfd, 0, SEEK_SET) < 0) { pop_error("mailbox: lseek"); + free(mbuf); return -1; }; /* parse mailbox */ @@ -365,7 +373,7 @@ exit(1); }; fd_initfgets(); - if ((mcount = fd_fgets(mbuf, sizeof(mbuf), mailboxfd)) < 0) { + if ((mcount = fd_fgets(mbuf, MBUF_SIZE, mailboxfd)) < 0) { if (!compare) { unlock_mailbox(); mb_release(); @@ -376,14 +384,18 @@ send_error("mailbox is damaged"); exit(1); }; + free(mbuf); return -1; }; if (mcount == 0) { if (!compare) { msgnr = 0; + free(mbuf); return 0; - } else + } else { + free(mbuf); return ((msgnr == 0) ? 0 : -1); + } }; if ((mcount > 0) && (mcount < (5 + 2 + sizeof(msgdate)))) { if (!compare) { @@ -395,6 +407,7 @@ send_error("mailbox is damaged"); exit(1); }; + free(mbuf); return -1; }; if ((mcount > 0) && (strncmp(mbuf, "From ", 5) != 0)) { @@ -407,6 +420,7 @@ send_error("mailbox is damaged"); exit(1); }; + free(mbuf); return -1; }; tmp2 = mcount; @@ -434,12 +448,16 @@ (tmp->where != tmpwhere) || (tmp->from_size != tmpfrom_size) || (memcmp(tmp->digest, tmpdigest, 16) != 0) || - (messages[tmpmsgnr - 1].msg_time != tmpmsg_time)) - return -1; + (messages[tmpmsgnr - 1].msg_time != tmpmsg_time)) { + free(mbuf); + return -1; + } }; }; - if (compare && (tmpmsgnr >= msgnr)) + if (compare && (tmpmsgnr >= msgnr)) { + free(mbuf); return 0; /* messages added only */ + } tmpfrom_where = act_ofs - mcount; tmpmsgnr++; if (!compare) @@ -460,7 +478,7 @@ } else memcpy(msgdate, mbuf + mcount - sizeof(msgdate), sizeof(msgdate)); while (mbuf[mcount - 1] != '\n') { - mcount = fd_fgets(mbuf, sizeof(mbuf), mailboxfd); + mcount = fd_fgets(mbuf, MBUF_SIZE, mailboxfd); if (mcount <= 0) break; if (mcount < (sizeof(msgdate))) { @@ -485,6 +503,7 @@ send_error("mailbox is damaged"); exit(1); }; + free(mbuf); return -1; }; newline = 1; @@ -507,7 +526,7 @@ newline = 0; }; tmp2 = mcount; - mcount = fd_fgets(mbuf, sizeof(mbuf), mailboxfd); + mcount = fd_fgets(mbuf, MBUF_SIZE, mailboxfd); }; if (mcount < 0) { if (!compare) { @@ -520,6 +539,7 @@ send_error("mailbox is damaged"); exit(1); }; + free(mbuf); return -1; }; if (tmp2 > 0) @@ -533,6 +553,7 @@ send_error("mailbox is damaged"); exit(1); }; + free(mbuf); return -1; }; tmp = (struct mb_message *)(messages[tmpmsgnr - 1].md_specific); @@ -554,9 +575,12 @@ (tmp->where != tmpwhere) || (tmp->from_size != tmpfrom_size) || (memcmp(tmp->digest, tmpdigest, 16) != 0) || - (messages[tmpmsgnr - 1].msg_time != tmpmsg_time)) - return -1; + (messages[tmpmsgnr - 1].msg_time != tmpmsg_time)) { + free(mbuf); + return -1; + } }; + free(mbuf); return 0; }