diff options
author | Eric Faurot <eric@cvs.openbsd.org> | 2013-01-31 18:34:44 +0000 |
---|---|---|
committer | Eric Faurot <eric@cvs.openbsd.org> | 2013-01-31 18:34:44 +0000 |
commit | ab4613f907295576d57cc97e4e21ecdcfec9b147 (patch) | |
tree | 88d4069d85291dd9d4c1e812fd81d8d74c555be3 /usr.sbin | |
parent | 607436a02a6968961ade01e8dfc0543ce3a1362a (diff) |
assorted fixes spotted by Coverity.
some log message updates.
ok gilles@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/smtpd/aldap.c | 19 | ||||
-rw-r--r-- | usr.sbin/smtpd/aliases.c | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/enqueue.c | 8 | ||||
-rw-r--r-- | usr.sbin/smtpd/envelope.c | 5 | ||||
-rw-r--r-- | usr.sbin/smtpd/expand.c | 11 | ||||
-rw-r--r-- | usr.sbin/smtpd/forward.c | 3 | ||||
-rw-r--r-- | usr.sbin/smtpd/imsgproc.c | 6 | ||||
-rw-r--r-- | usr.sbin/smtpd/lka_session.c | 10 | ||||
-rw-r--r-- | usr.sbin/smtpd/makemap.c | 9 | ||||
-rw-r--r-- | usr.sbin/smtpd/mfa_session.c | 5 | ||||
-rw-r--r-- | usr.sbin/smtpd/mproc.c | 21 | ||||
-rw-r--r-- | usr.sbin/smtpd/mta_session.c | 20 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue_fsqueue.c | 17 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue_ram.c | 3 | ||||
-rw-r--r-- | usr.sbin/smtpd/scheduler.c | 5 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.c | 19 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 3 | ||||
-rw-r--r-- | usr.sbin/smtpd/table_db.c | 16 | ||||
-rw-r--r-- | usr.sbin/smtpd/table_ldap.c | 14 | ||||
-rw-r--r-- | usr.sbin/smtpd/table_sqlite.c | 3 | ||||
-rw-r--r-- | usr.sbin/smtpd/to.c | 9 | ||||
-rw-r--r-- | usr.sbin/smtpd/util.c | 6 |
22 files changed, 139 insertions, 77 deletions
diff --git a/usr.sbin/smtpd/aldap.c b/usr.sbin/smtpd/aldap.c index 38e09fc8632..bf470853b9b 100644 --- a/usr.sbin/smtpd/aldap.c +++ b/usr.sbin/smtpd/aldap.c @@ -1,5 +1,5 @@ -/* $Id: aldap.c,v 1.3 2013/01/26 09:37:22 gilles Exp $ */ -/* $OpenBSD: aldap.c,v 1.3 2013/01/26 09:37:22 gilles Exp $ */ +/* $Id: aldap.c,v 1.4 2013/01/31 18:34:43 eric Exp $ */ +/* $OpenBSD: aldap.c,v 1.4 2013/01/31 18:34:43 eric Exp $ */ /* * Copyright (c) 2008 Alexander Schrijver <aschrijver@openbsd.org> @@ -324,10 +324,13 @@ aldap_parse_page_control(struct ber_element *control, size_t len) ber_scanf_elements(control, "ss", &oid, &encoded); ber_set_readbuf(&b, encoded, control->be_next->be_len); elm = ber_read_elements(&b, NULL); + if (elm == NULL) { + ber_free(&b); + return NULL; + } if ((page = malloc(sizeof(struct aldap_page_control))) == NULL) { - if (elm != NULL) - ber_free_elements(elm); + ber_free_elements(elm); ber_free(&b); return NULL; } @@ -336,8 +339,7 @@ aldap_parse_page_control(struct ber_element *control, size_t len) page->cookie_len = elm->be_sub->be_next->be_len; if ((page->cookie = malloc(page->cookie_len)) == NULL) { - if (elm != NULL) - ber_free_elements(elm); + ber_free_elements(elm); ber_free(&b); free(page); return NULL; @@ -569,8 +571,9 @@ aldap_parse_url(char *url, struct aldap_url *lu) const char *errstr = NULL; int i; - if ((lu->buffer = p = strdup(url)) == NULL) + if ((lu->buffer = strdup(url)) == NULL) return (-1); + p = lu->buffer; /* protocol */ if (strncasecmp(LDAP_URL, p, strlen(LDAP_URL)) != 0) @@ -822,7 +825,7 @@ ldap_do_parse_search_filter(struct ber_element *prev, char **cpp) ber_set_header(root, BER_CLASS_CONTEXT, LDAP_FILT_NOT); cp++; /* now points to sub-filter */ - if ((elm = ldap_do_parse_search_filter(root, &cp)) == NULL) + if (ldap_do_parse_search_filter(root, &cp) == NULL) goto bad; if (*cp != ')') /* trailing `)` of filter */ diff --git a/usr.sbin/smtpd/aliases.c b/usr.sbin/smtpd/aliases.c index c2502fa4c8f..002b0be7eb3 100644 --- a/usr.sbin/smtpd/aliases.c +++ b/usr.sbin/smtpd/aliases.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aliases.c,v 1.59 2013/01/26 09:37:23 gilles Exp $ */ +/* $OpenBSD: aliases.c,v 1.60 2013/01/31 18:34:43 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -185,7 +185,7 @@ aliases_expand_include(struct expand *expand, const char *filename) FILE *fp; char *line; size_t len, lineno = 0; - char delim[] = { '\\', '#' }; + char delim[3] = { '\\', '#', '\0' }; fp = fopen(filename, "r"); if (fp == NULL) { diff --git a/usr.sbin/smtpd/enqueue.c b/usr.sbin/smtpd/enqueue.c index 8d332544199..0413d27927d 100644 --- a/usr.sbin/smtpd/enqueue.c +++ b/usr.sbin/smtpd/enqueue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: enqueue.c,v 1.66 2013/01/26 09:37:23 gilles Exp $ */ +/* $OpenBSD: enqueue.c,v 1.67 2013/01/31 18:34:43 eric Exp $ */ /* * Copyright (c) 2005 Henning Brauer <henning@bulabula.org> @@ -23,6 +23,7 @@ #include <sys/socket.h> #include <sys/tree.h> #include <sys/types.h> +#include <sys/stat.h> #include <ctype.h> #include <err.h> @@ -680,6 +681,8 @@ rcpt_add(char *addr) if ((p = strchr(addr, ',')) != NULL) *p++ = '\0'; msg.rcpts[msg.rcpt_cnt++] = qualify_addr(addr); + if (p == NULL) + break; addr = p; } } @@ -732,6 +735,7 @@ enqueue_offline(int argc, char *argv[]) char path[MAXPATHLEN]; FILE *fp; int i, fd, ch; + mode_t omode; if (ckdir(PATH_SPOOL PATH_OFFLINE, 01777, 0, 0, 0) == 0) errx(1, "error in offline directory setup"); @@ -740,12 +744,14 @@ enqueue_offline(int argc, char *argv[]) PATH_OFFLINE, (long long int) time(NULL))) err(1, "snprintf"); + omode = umask(7077); if ((fd = mkstemp(path)) == -1 || (fp = fdopen(fd, "w+")) == NULL) { warn("cannot create temporary file %s", path); if (fd != -1) unlink(path); exit(1); } + umask(omode); for (i = 1; i < argc; i++) { if (strchr(argv[i], '|') != NULL) { diff --git a/usr.sbin/smtpd/envelope.c b/usr.sbin/smtpd/envelope.c index 3a13db31b36..da8cdbfd3ac 100644 --- a/usr.sbin/smtpd/envelope.c +++ b/usr.sbin/smtpd/envelope.c @@ -1,4 +1,4 @@ -/* $OpenBSD: envelope.c,v 1.18 2013/01/26 09:37:23 gilles Exp $ */ +/* $OpenBSD: envelope.c,v 1.19 2013/01/31 18:34:43 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@poolp.org> @@ -558,6 +558,9 @@ ascii_load_sockaddr(struct sockaddr_storage *ss, char *buf) struct sockaddr_in6 ssin6; struct sockaddr_in ssin; + bzero(&ssin, sizeof ssin); + bzero(&ssin6, sizeof ssin6); + if (!strcmp("local", buf)) { ss->ss_family = AF_LOCAL; } diff --git a/usr.sbin/smtpd/expand.c b/usr.sbin/smtpd/expand.c index 434d08cdb37..06c525a3a5b 100644 --- a/usr.sbin/smtpd/expand.c +++ b/usr.sbin/smtpd/expand.c @@ -1,4 +1,4 @@ -/* $OpenBSD: expand.c,v 1.19 2013/01/26 09:37:23 gilles Exp $ */ +/* $OpenBSD: expand.c,v 1.20 2013/01/31 18:34:43 eric Exp $ */ /* * Copyright (c) 2009 Gilles Chehade <gilles@poolp.org> @@ -68,7 +68,7 @@ expand_insert(struct expand *expand, struct expandnode *node) } void -expand_free(struct expand *expand) +expand_clear(struct expand *expand) { struct expandnode *xn; @@ -82,6 +82,13 @@ expand_free(struct expand *expand) } } +void +expand_free(struct expand *expand) +{ + expand_clear(expand); + free(expand); +} + int expand_cmp(struct expandnode *e1, struct expandnode *e2) { diff --git a/usr.sbin/smtpd/forward.c b/usr.sbin/smtpd/forward.c index 1738c9318ff..b1a498597e8 100644 --- a/usr.sbin/smtpd/forward.c +++ b/usr.sbin/smtpd/forward.c @@ -1,4 +1,4 @@ -/* $OpenBSD: forward.c,v 1.33 2013/01/26 09:37:23 gilles Exp $ */ +/* $OpenBSD: forward.c,v 1.34 2013/01/31 18:34:43 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -67,6 +67,7 @@ forwards_get(int fd, struct expand *expand) goto end; } + lineno = 0; while ((line = fparseln(fp, &len, &lineno, NULL, 0)) != NULL) { if (! expand_line(expand, line, 0)) { log_info("info: parse error in forward file"); diff --git a/usr.sbin/smtpd/imsgproc.c b/usr.sbin/smtpd/imsgproc.c index 18a22ebf387..b89b4b140c1 100644 --- a/usr.sbin/smtpd/imsgproc.c +++ b/usr.sbin/smtpd/imsgproc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imsgproc.c,v 1.1 2013/01/26 09:37:23 gilles Exp $ */ +/* $OpenBSD: imsgproc.c,v 1.2 2013/01/31 18:34:43 eric Exp $ */ /* * Copyright (c) 2012 Gilles Chehade <gilles@poolp.org> @@ -87,6 +87,10 @@ err: proc->name, proc->path); close(sp[0]); close(sp[1]); + free(proc->path); + free(proc->name); + free(proc->ibuf); + free(proc); return NULL; } diff --git a/usr.sbin/smtpd/lka_session.c b/usr.sbin/smtpd/lka_session.c index 5b4f09fcf53..5a71fd494bf 100644 --- a/usr.sbin/smtpd/lka_session.c +++ b/usr.sbin/smtpd/lka_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka_session.c,v 1.52 2013/01/28 11:09:53 gilles Exp $ */ +/* $OpenBSD: lka_session.c,v 1.53 2013/01/31 18:34:43 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@poolp.org> @@ -199,7 +199,7 @@ lka_resume(struct lka_session *lks) m_close(p_queue); } - expand_free(&lks->expand); + expand_clear(&lks->expand); tree_xpop(&sessions, lks->id); free(lks); } @@ -644,7 +644,11 @@ lka_expand_format(char *buf, size_t len, const struct envelope *ep, /* extract token from %{token} */ if ((size_t)(ebuf - pbuf) - 1 >= sizeof token) return 0; - *strchr(memcpy(token, pbuf+2, ebuf-pbuf-1), '}') = '\0'; + + memcpy(token, pbuf+2, ebuf-pbuf-1); + if (strchr(token, '}') == NULL) + return 0; + *strchr(token, '}') = '\0'; exptoklen = lka_expand_token(exptok, sizeof exptok, token, ep, ui); diff --git a/usr.sbin/smtpd/makemap.c b/usr.sbin/smtpd/makemap.c index c8382f7593c..a624185a1d6 100644 --- a/usr.sbin/smtpd/makemap.c +++ b/usr.sbin/smtpd/makemap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: makemap.c,v 1.42 2013/01/26 09:37:23 gilles Exp $ */ +/* $OpenBSD: makemap.c,v 1.43 2013/01/31 18:34:43 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -90,8 +90,8 @@ main(int argc, char *argv[]) char *conf; int ch; DBTYPE dbtype = DB_HASH; - char *execname; char *p; + mode_t omode; log_init(1); @@ -101,7 +101,6 @@ main(int argc, char *argv[]) opts = "ho:t:d:"; if (mode == P_NEWALIASES) opts = "f:h"; - execname = argv[0]; while ((ch = getopt(argc, argv, opts)) != -1) { switch (ch) { @@ -153,7 +152,7 @@ main(int argc, char *argv[]) errx(1, "database name too long"); } - execlp(execname, execname, "-d", argv[0], "-o", dbname, "-", + execlp("makemap", "makemap", "-d", argv[0], "-o", dbname, "-", NULL); err(1, "execlp"); } @@ -180,8 +179,10 @@ main(int argc, char *argv[]) if (! bsnprintf(dbname, sizeof(dbname), "%s.XXXXXXXXXXX", oflag)) errx(1, "path too long"); + omode = umask(7077); if (mkstemp(dbname) == -1) err(1, "mkstemp"); + umask(omode); db = dbopen(dbname, O_EXLOCK|O_RDWR|O_SYNC, 0644, dbtype, NULL); if (db == NULL) { diff --git a/usr.sbin/smtpd/mfa_session.c b/usr.sbin/smtpd/mfa_session.c index 4bae035dec3..3d9eee975e7 100644 --- a/usr.sbin/smtpd/mfa_session.c +++ b/usr.sbin/smtpd/mfa_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mfa_session.c,v 1.13 2013/01/26 09:37:23 gilles Exp $ */ +/* $OpenBSD: mfa_session.c,v 1.14 2013/01/31 18:34:43 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@poolp.org> @@ -394,6 +394,7 @@ mfa_drain_query(struct mfa_query *q) free(q->smtp.response); } + TAILQ_REMOVE(&q->session->queries, q, entry); /* If the query was a disconnect event, the session can be freed */ if (q->type == HOOK_DISCONNECT) { /* XXX assert prev == NULL */ @@ -401,8 +402,6 @@ mfa_drain_query(struct mfa_query *q) } log_trace(TRACE_MFA, "mfa: freeing query %016" PRIx64, q->qid); - - TAILQ_REMOVE(&q->session->queries, q, entry); free(q); } diff --git a/usr.sbin/smtpd/mproc.c b/usr.sbin/smtpd/mproc.c index b37cfe8be08..0ca56245c80 100644 --- a/usr.sbin/smtpd/mproc.c +++ b/usr.sbin/smtpd/mproc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mproc.c,v 1.1 2013/01/26 09:37:23 gilles Exp $ */ +/* $OpenBSD: mproc.c,v 1.2 2013/01/31 18:34:43 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@faurot.net> @@ -171,8 +171,11 @@ mproc_dispatch(int fd, short event, void *arg) } for (;;) { - if ((n = imsg_get(&p->imsgbuf, &imsg)) == -1) - fatal("imsg_get"); + if ((n = imsg_get(&p->imsgbuf, &imsg)) == -1) { + log_warn("fatal: %s: error in imsg_get for %s", + proc_name(smtpd_process), p->name); + fatalx(NULL); + } if (n == 0) break; @@ -316,11 +319,11 @@ m_create(struct mproc *p, uint32_t type, uint32_t peerid, pid_t pid, int fd, reqlen = len; p->ibuf = imsg_create(&p->imsgbuf, type, peerid, pid, len); - /* Is this a problem with imsg? */ - p->ibuf->fd = fd; - if (p->ibuf == NULL) fatal("imsg_create"); + + /* Is this a problem with imsg? */ + p->ibuf->fd = fd; } void @@ -346,6 +349,12 @@ m_close(struct mproc *p) proc_name(smtpd_process), proc_name(p->proc), imsg_to_str(reqtype)); + else if (verbose & TRACE_IMSGSIZE) + log_debug("msg-len: ok %zu : %s -> %s : %s", + p->ibuf->wpos - IMSG_HEADER_SIZE, + proc_name(smtpd_process), + proc_name(p->proc), + imsg_to_str(reqtype)); p->msg_out += 1; p->bytes_queued += p->ibuf->wpos; diff --git a/usr.sbin/smtpd/mta_session.c b/usr.sbin/smtpd/mta_session.c index 71c85947033..5258a0e9408 100644 --- a/usr.sbin/smtpd/mta_session.c +++ b/usr.sbin/smtpd/mta_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mta_session.c,v 1.30 2013/01/28 16:40:22 eric Exp $ */ +/* $OpenBSD: mta_session.c,v 1.31 2013/01/31 18:34:43 eric Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -1027,14 +1027,6 @@ mta_error(struct mta_session *s, const char *fmt, ...) char *error; int len; - /* - * If not connected yet, and the error is not local, just ignore it - * and try to reconnect. - */ - if (s->state == MTA_INIT && - (errno == ETIMEDOUT || errno == ECONNREFUSED)) - return; - va_start(ap, fmt); if ((len = vasprintf(&error, fmt, ap)) == -1) fatal("mta: vasprintf"); @@ -1047,6 +1039,16 @@ mta_error(struct mta_session *s, const char *fmt, ...) else log_info("smtp-out: Error on session %016"PRIx64 ": %s", s->id, error); + /* + * If not connected yet, and the error is not local, just ignore it + * and try to reconnect. + */ + if (s->state == MTA_INIT && + (errno == ETIMEDOUT || errno == ECONNREFUSED)) { + log_debug("debug: mta: not reporting route error yet"); + free(error); + return; + } mta_route_error(s->relay, s->route); diff --git a/usr.sbin/smtpd/queue_fsqueue.c b/usr.sbin/smtpd/queue_fsqueue.c index d640f5b6ef2..c4a10fcbe54 100644 --- a/usr.sbin/smtpd/queue_fsqueue.c +++ b/usr.sbin/smtpd/queue_fsqueue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue_fsqueue.c,v 1.57 2013/01/26 09:37:23 gilles Exp $ */ +/* $OpenBSD: queue_fsqueue.c,v 1.58 2013/01/31 18:34:43 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@poolp.org> @@ -157,8 +157,9 @@ fsqueue_envelope_dump(char *dest, char *evpbuf, size_t evplen, int do_atomic, in log_warn("warn: fsqueue_envelope_dump: fsync"); goto tempfail; } - if (fclose(fp)) { + if (fclose(fp) != 0) { log_warn("warn: fsqueue_envelope_dump: fclose"); + fp = NULL; goto tempfail; } fp = NULL; @@ -229,7 +230,7 @@ fsqueue_envelope_load(uint64_t evpid, char *buf, size_t len) { char pathname[MAXPATHLEN]; FILE *fp; - ssize_t r; + size_t r; fsqueue_envelope_path(evpid, pathname, sizeof(pathname)); @@ -241,7 +242,14 @@ fsqueue_envelope_load(uint64_t evpid, char *buf, size_t len) } r = fread(buf, 1, len, fp); - + if (r) { + if (r == len) { + log_warn("warn: fsqueue_envelope_load: too large"); + r = 0; + } + else + buf[r] = '\0'; + } fclose(fp); return (r); @@ -297,6 +305,7 @@ fsqueue_envelope_walk(uint64_t *evpid, char *buf, size_t len) hdl = fsqueue_qwalk_new(); if (fsqueue_qwalk(hdl, evpid)) { + bzero(buf, len); r = fsqueue_envelope_load(*evpid, buf, len); if (r) { msgid = evpid_to_msgid(*evpid); diff --git a/usr.sbin/smtpd/queue_ram.c b/usr.sbin/smtpd/queue_ram.c index 5308dd50d1a..ab80811435e 100644 --- a/usr.sbin/smtpd/queue_ram.c +++ b/usr.sbin/smtpd/queue_ram.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue_ram.c,v 1.1 2013/01/26 09:37:23 gilles Exp $ */ +/* $OpenBSD: queue_ram.c,v 1.2 2013/01/31 18:34:43 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> @@ -240,6 +240,7 @@ queue_ram_envelope(enum queue_op qop, uint64_t *evpid, char *buf, size_t len) evp->buf = malloc(len); if (evp->buf == NULL) { log_warn("warn: queue_ram_envelope: malloc"); + free(evp); return (0); } memmove(evp->buf, buf, len); diff --git a/usr.sbin/smtpd/scheduler.c b/usr.sbin/smtpd/scheduler.c index c99a3c7aa42..dd8f75f44b0 100644 --- a/usr.sbin/smtpd/scheduler.c +++ b/usr.sbin/smtpd/scheduler.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scheduler.c,v 1.25 2013/01/26 09:37:23 gilles Exp $ */ +/* $OpenBSD: scheduler.c,v 1.26 2013/01/31 18:34:43 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -352,7 +352,8 @@ scheduler(void) evtimer_set(&env->sc_ev, scheduler_timeout, NULL); scheduler_reset_events(); - event_dispatch(); + if (event_dispatch() < 0) + fatal("event_dispatch"); scheduler_shutdown(); return (0); diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c index cb294174f1d..636307e90c3 100644 --- a/usr.sbin/smtpd/smtpd.c +++ b/usr.sbin/smtpd/smtpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.c,v 1.185 2013/01/28 11:09:53 gilles Exp $ */ +/* $OpenBSD: smtpd.c,v 1.186 2013/01/31 18:34:43 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -35,6 +35,7 @@ #include <event.h> #include <fcntl.h> #include <imsg.h> +#include <inttypes.h> #include <login_cap.h> #include <paths.h> #include <pwd.h> @@ -542,6 +543,9 @@ parent_sig_handler(int sig, short event, void *p) } if (child->cause) free(child->cause); + log_debug("debug: smtpd: mda process done " + "for session %016"PRIx64 ": %s", + child->mda_id, cause); m_create(p_mda, IMSG_MDA_DONE, 0, 0, child->mda_out, 32 + strlen(cause)); m_add_id(p_mda, child->mda_id); @@ -792,7 +796,7 @@ main(int argc, char *argv[]) continue; ssl = NULL; if (! ssl_load_certfile(&ssl, "/etc/mail/certs", - r->r_value.relayhost.cert, F_CCERT) < 0) + r->r_value.relayhost.cert, F_CCERT)) errx(1, "cannot load certificate: %s", r->r_value.relayhost.cert); dict_set(env->sc_ssl_dict, ssl->ssl_name, ssl); } @@ -898,7 +902,6 @@ static void purge_task(int fd, short ev, void *arg) { DIR *d; - struct dirent *de; int n; uid_t uid; gid_t gid; @@ -907,7 +910,7 @@ purge_task(int fd, short ev, void *arg) n = 0; if ((d = opendir(PATH_SPOOL PATH_PURGE))) { - while ((de = readdir(d)) != NULL) + while (readdir(d) != NULL) n++; closedir(d); } else @@ -949,9 +952,10 @@ forkmda(struct mproc *p, uint64_t id, struct deliver *deliver) struct child *child; pid_t pid; int n, allout, pipefd[2]; + mode_t omode; - log_debug("debug: forkmda: to \"%s\" as %s", - deliver->to, deliver->user); + log_debug("debug: smtpd: forking mda for session %016"PRIx64 + ": \"%s\" as %s", id, deliver->to, deliver->user); db = delivery_backend_lookup(deliver->mode); if (db == NULL) @@ -984,7 +988,9 @@ forkmda(struct mproc *p, uint64_t id, struct deliver *deliver) /* prepare file which captures stdout and stderr */ strlcpy(sfn, "/tmp/smtpd.out.XXXXXXXXXXX", sizeof(sfn)); + omode = umask(7077); allout = mkstemp(sfn); + umask(omode); if (allout < 0) { n = snprintf(ebuf, sizeof ebuf, "mkstemp: %s", strerror(errno)); if (seteuid(0) < 0) @@ -1007,6 +1013,7 @@ forkmda(struct mproc *p, uint64_t id, struct deliver *deliver) m_create(p_mda, IMSG_MDA_DONE, 0, 0, -1, 128); m_add_id(p_mda, id); m_add_string(p_mda, ebuf); + m_close(p_mda); close(pipefd[0]); close(pipefd[1]); close(allout); diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index e3e07142c6e..82107731448 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.401 2013/01/31 18:24:47 eric Exp $ */ +/* $OpenBSD: smtpd.h,v 1.402 2013/01/31 18:34:43 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -1106,6 +1106,7 @@ int envelope_dump_buffer(const struct envelope *, char *, size_t); int expand_cmp(struct expandnode *, struct expandnode *); void expand_insert(struct expand *, struct expandnode *); struct expandnode *expand_lookup(struct expand *, struct expandnode *); +void expand_clear(struct expand *); void expand_free(struct expand *); int expand_line(struct expand *, const char *, int); RB_PROTOTYPE(expandtree, expandnode, nodes, expand_cmp); diff --git a/usr.sbin/smtpd/table_db.c b/usr.sbin/smtpd/table_db.c index 0688f23bd03..732faf7a2d7 100644 --- a/usr.sbin/smtpd/table_db.c +++ b/usr.sbin/smtpd/table_db.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table_db.c,v 1.1 2013/01/26 09:37:24 gilles Exp $ */ +/* $OpenBSD: table_db.c,v 1.2 2013/01/31 18:34:43 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@poolp.org> @@ -83,13 +83,13 @@ struct dbhandle { static int table_db_config(struct table *table, const char *config) { - DB *db; + struct dbhandle *handle; - db = table_db_open(table); - if (db == NULL) + handle = table_db_open(table); + if (handle == NULL) return 0; - table_db_close(db); + table_db_close(handle); return 1; } @@ -103,7 +103,6 @@ table_db_update(struct table *table) return 0; table_db_close(table->t_handle); - free(table->t_handle); table->t_handle = handle; return 1; } @@ -142,6 +141,7 @@ table_db_close(void *hdl) { struct dbhandle *handle = hdl; handle->db->close(handle->db); + free(handle); } static int @@ -174,8 +174,10 @@ table_db_lookup(void *hdl, const char *key, enum table_service service, if (line == NULL) return 0; - if (retp == NULL) + if (retp == NULL) { + free(line); return 1; + } ret = 0; switch (service) { diff --git a/usr.sbin/smtpd/table_ldap.c b/usr.sbin/smtpd/table_ldap.c index c42b7abbe89..0f3ccf20003 100644 --- a/usr.sbin/smtpd/table_ldap.c +++ b/usr.sbin/smtpd/table_ldap.c @@ -171,9 +171,11 @@ table_ldap_open(struct table *table) return tlh; err: - if (tlh->aldap != NULL) - aldap_close(tlh->aldap); - free(tlh); + if (tlh) { + if (tlh->aldap != NULL) + aldap_close(tlh->aldap); + free(tlh); + } if (message != NULL) aldap_freemsg(message); return NULL; @@ -288,8 +290,6 @@ error: ret = -1; end: - if (pg) - aldap_freepage(pg); if (m) aldap_freemsg(m); log_debug("debug: table_ldap_internal_query: filter=%s, ret=%d", filter, ret); @@ -593,6 +593,7 @@ ldap_client_connect(const char *addr) warnx("aldap_parse_url fail"); goto err; } + url = NULL; bzero(&hints, sizeof(hints)); hints.ai_family = PF_UNSPEC; @@ -628,11 +629,10 @@ ldap_client_connect(const char *addr) } close(fd); + fd = -1; } err: - if (fd != -1) - close(fd); free(url); return NULL; } diff --git a/usr.sbin/smtpd/table_sqlite.c b/usr.sbin/smtpd/table_sqlite.c index 0d506c217f0..b2ec3141452 100644 --- a/usr.sbin/smtpd/table_sqlite.c +++ b/usr.sbin/smtpd/table_sqlite.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table_sqlite.c,v 1.1 2013/01/26 09:37:24 gilles Exp $ */ +/* $OpenBSD: table_sqlite.c,v 1.2 2013/01/31 18:34:43 eric Exp $ */ /* * Copyright (c) 2012 Gilles Chehade <gilles@poolp.org> @@ -112,6 +112,7 @@ table_sqlite_open(struct table *table) if (sqlite3_open(dbpath, &tsh->ppDb) != SQLITE_OK) { log_warnx("table_sqlite: open: %s", sqlite3_errmsg(tsh->ppDb)); + free(tsh); return NULL; } diff --git a/usr.sbin/smtpd/to.c b/usr.sbin/smtpd/to.c index d3f3327db88..e93a6fa50ea 100644 --- a/usr.sbin/smtpd/to.c +++ b/usr.sbin/smtpd/to.c @@ -1,4 +1,4 @@ -/* $OpenBSD: to.c,v 1.1 2013/01/26 09:37:24 gilles Exp $ */ +/* $OpenBSD: to.c,v 1.2 2013/01/31 18:34:43 eric Exp $ */ /* * Copyright (c) 2009 Jacek Masiulaniec <jacekm@dobremiasto.net> @@ -266,23 +266,22 @@ text_to_netaddr(struct netaddr *netaddr, const char *s) struct sockaddr_in6 ssin6; int bits; + bzero(&ssin, sizeof(struct sockaddr_in)); + bzero(&ssin6, sizeof(struct sockaddr_in6)); + if (strncmp("IPv6:", s, 5) == 0) s += 5; if (strchr(s, '/') != NULL) { /* dealing with netmask */ - - bzero(&ssin, sizeof(struct sockaddr_in)); bits = inet_net_pton(AF_INET, s, &ssin.sin_addr, sizeof(struct in_addr)); - if (bits != -1) { ssin.sin_family = AF_INET; memcpy(&ss, &ssin, sizeof(ssin)); ss.ss_len = sizeof(struct sockaddr_in); } else { - bzero(&ssin6, sizeof(struct sockaddr_in6)); bits = inet_net_pton(AF_INET6, s, &ssin6.sin6_addr, sizeof(struct in6_addr)); if (bits == -1) { diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c index 1586513e79c..d6a30802644 100644 --- a/usr.sbin/smtpd/util.c +++ b/usr.sbin/smtpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.90 2013/01/26 09:37:24 gilles Exp $ */ +/* $OpenBSD: util.c,v 1.91 2013/01/31 18:34:43 eric Exp $ */ /* * Copyright (c) 2000,2001 Markus Friedl. All rights reserved. @@ -365,14 +365,16 @@ mktmpfile(void) { char path[MAXPATHLEN]; int fd; + mode_t omode; if (! bsnprintf(path, sizeof(path), "%s/smtpd.XXXXXXXXXX", PATH_TEMPORARY)) err(1, "snprintf"); + omode = umask(7077); if ((fd = mkstemp(path)) == -1) err(1, "cannot create temporary file %s", path); - + umask(omode); unlink(path); return (fd); } |