#define BADHOST 2
#include <stddef.h>
+#include <unistd.h>
struct mailname {
struct mailname *m_next;
char *getname(char *);
char *adrformat(struct mailname *);
struct mailname *getm(char *, char *, int, int, char *);
-size_t getmboxes(char *, struct mailname **);
+ssize_t getmboxes(char *, struct mailname **);
* number of parsed addresses. element is set to
* the last parsed addresse.
*/
-size_t
+ssize_t
getmboxes(char *line, struct mailname **element)
{
- struct mailname *mp, *next;
+ struct mailname *mp, *next, *first;
char *cp;
size_t i = 0;
- next = (*element)->m_next;
+ first = *element;
+ next = first->m_next;
while ((cp = getname(line))) {
mp = getm(cp, NULL, 0, AD_HOST, NULL);
+ if (mp == NULL) {
+ goto error;
+ }
(*element)->m_next = mp;
*element = mp;
i++;
(*element)->m_next = next;
return i;
+error:
+ while (first->m_next != NULL && first->m_next != next) {
+ mp = first->m_next;
+ first->m_next = mp->m_next;
+ free(mp);
+ }
+ first->m_next = next;
+ return -1;
}
int i;
struct headers *hdr;
struct mailname addr_start, *addr_end;
- size_t addrc;
+ size_t addrc = 0;
+ ssize_t ret;
addr_end = &addr_start;
addr_end->m_next = NULL;
return;
}
- addrc = getmboxes(str, &addr_end);
+ if ((ret = getmboxes(str, &addr_end)) < 0) {
+ adios(EX_DATAERR, NULL, "can't parse address: %s", str);
+ }
+
+ addrc += ret;
if (aliasflg) {
addrc += do_aliasing(&addr_start, &addr_end);
if (hdr->set & MFRM) {
struct mailname *mp = NULL;
struct mailname *my = NULL;
- unsigned int fromcnt = 0;
/* needed because the address parser holds global state */
ismymbox(NULL);
my = mp;
}
}
- fromcnt++;
}
- if (fromcnt > 1) {
+ if (addrc > 1) {
sender = my;
}
}
struct mailname *prev, *cur;
char *cp;
size_t i = 0;
+ ssize_t e;
prev = start;
cur = prev->m_next;
cp = akvalue(cur->m_mbox);
if (strcmp(cp, cur->m_mbox) != 0) {
prev->m_next = cur->m_next;
- i += getmboxes(cp, &prev);
+ if ((e = getmboxes(cp, &prev)) < 0) {
+ goto error;
+ }
+ i += e;
i -= 1;
mnfree(cur);
} else {
}
*end = prev;
return i;
+error:
+ adios(EX_CONFIG, NULL, "can't parse alias %s: %s", cur->m_mbox, cp);
+ return 0; /* not reached */
}