diff options
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r-- | usr.sbin/smtpd/control.c | 5 | ||||
-rw-r--r-- | usr.sbin/smtpd/dns.c | 11 | ||||
-rw-r--r-- | usr.sbin/smtpd/enqueue.c | 18 | ||||
-rw-r--r-- | usr.sbin/smtpd/forward.c | 5 | ||||
-rw-r--r-- | usr.sbin/smtpd/lka.c | 39 | ||||
-rw-r--r-- | usr.sbin/smtpd/makemap.c | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/mta.c | 23 | ||||
-rw-r--r-- | usr.sbin/smtpd/parse.y | 17 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue_shared.c | 65 | ||||
-rw-r--r-- | usr.sbin/smtpd/runner.c | 11 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtp.c | 12 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.c | 25 | ||||
-rw-r--r-- | usr.sbin/smtpd/util.c | 6 |
13 files changed, 135 insertions, 106 deletions
diff --git a/usr.sbin/smtpd/control.c b/usr.sbin/smtpd/control.c index 95c858550d5..0869fb27177 100644 --- a/usr.sbin/smtpd/control.c +++ b/usr.sbin/smtpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.13 2009/02/17 22:49:22 jacekm Exp $ */ +/* $OpenBSD: control.c,v 1.14 2009/02/22 11:44:29 form Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -707,7 +707,8 @@ control_dispatch_queue(int sig, short event, void *p) } else { ss->msg.session_id = ss->id; - strlcpy(ss->msg.message_id, ss->u.msgid, MAXPATHLEN); + strlcpy(ss->msg.message_id, ss->u.msgid, + sizeof(ss->msg.message_id)); imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, &ss->msg, sizeof(struct message)); } diff --git a/usr.sbin/smtpd/dns.c b/usr.sbin/smtpd/dns.c index 05af9ae1ca0..433f9396917 100644 --- a/usr.sbin/smtpd/dns.c +++ b/usr.sbin/smtpd/dns.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dns.c,v 1.9 2009/02/15 13:12:19 jacekm Exp $ */ +/* $OpenBSD: dns.c,v 1.10 2009/02/22 11:44:29 form Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -137,7 +137,8 @@ getmxbyname(char *name, char ***result) if (mxnb < sizeof(mxarray) / sizeof(struct mxrecord)) { if (strlcpy(mxarray[mxnb].hostname, expbuf, - MAXHOSTNAMELEN) >= MAXHOSTNAMELEN) + sizeof(mxarray[mxnb].hostname)) >= + sizeof(mxarray[mxnb].hostname)) return 0; mxarray[mxnb].priority = priority; } @@ -155,7 +156,8 @@ getmxbyname(char *name, char ***result) if (mxarray[j].priority > priority) { if (strlcpy(mxarray[j].hostname, expbuf, - MAXHOSTNAMELEN) >= MAXHOSTNAMELEN) + sizeof(mxarray[j].hostname)) >= + sizeof(mxarray[j].hostname)) return 0; mxarray[j].priority = priority; } @@ -183,7 +185,8 @@ getmxbyname(char *name, char ***result) ptr = (u_int8_t *)*result + (mxnb + 1) * sizeof(char *); for (i = 0; i < mxnb; ++i) { - strlcpy(ptr, mxarray[i].hostname, MAXHOSTNAMELEN); + strlcpy(ptr, mxarray[i].hostname, + strlen(mxarray[i].hostname) + 1); (*result)[i] = ptr; ptr += strlen(mxarray[i].hostname) + 1; } diff --git a/usr.sbin/smtpd/enqueue.c b/usr.sbin/smtpd/enqueue.c index 0a693a72501..48b1dd37b1f 100644 --- a/usr.sbin/smtpd/enqueue.c +++ b/usr.sbin/smtpd/enqueue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: enqueue.c,v 1.8 2009/01/29 15:20:34 gilles Exp $ */ +/* $OpenBSD: enqueue.c,v 1.9 2009/02/22 11:44:29 form Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -70,15 +70,14 @@ enqueue(int argc, char *argv[]) username = pw->pw_name; gethostname(hostname, sizeof(hostname)); - if (! bsnprintf(sender, MAX_PATH_SIZE, "%s@%s", - username, hostname)) + if (! bsnprintf(sender, sizeof(sender), "%s@%s", username, hostname)) errx(1, "sender address too long."); while ((ch = getopt(argc, argv, "f:i")) != -1) { switch (ch) { case 'f': - if (strlcpy(sender, optarg, MAX_PATH_SIZE) - >= MAX_PATH_SIZE) + if (strlcpy(sender, optarg, sizeof(sender)) + >= sizeof(sender)) errx(1, "sender address too long."); break; case 'i': @@ -93,8 +92,10 @@ enqueue(int argc, char *argv[]) bzero(&message, sizeof(struct message)); - strlcpy(message.session_helo, "localhost", MAXHOSTNAMELEN); - strlcpy(message.session_hostname, hostname, MAXHOSTNAMELEN); + strlcpy(message.session_helo, "localhost", + sizeof(message.session_helo)); + strlcpy(message.session_hostname, hostname, + sizeof(message.session_hostname)); /* build sender */ if (! recipient_to_path(&message.sender, sender)) @@ -266,7 +267,8 @@ enqueue_init(struct message *messagep) mp = imsg.data; messagep->session_id = mp->session_id; - strlcpy(messagep->message_id, mp->message_id, MAXPATHLEN); + strlcpy(messagep->message_id, mp->message_id, + sizeof(messagep->message_id)); return 1; } diff --git a/usr.sbin/smtpd/forward.c b/usr.sbin/smtpd/forward.c index 5af8f4725fa..ac2757a95fb 100644 --- a/usr.sbin/smtpd/forward.c +++ b/usr.sbin/smtpd/forward.c @@ -1,4 +1,4 @@ -/* $OpenBSD: forward.c,v 1.11 2009/01/29 21:50:10 form Exp $ */ +/* $OpenBSD: forward.c,v 1.12 2009/02/22 11:44:29 form Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -52,8 +52,7 @@ forwards_get(struct aliaseslist *aliases, char *username) if (pw == NULL) return 0; - if (snprintf(pathname, MAXPATHLEN, "%s/.forward", pw->pw_dir) - >= MAXPATHLEN) + if (! bsnprintf(pathname, sizeof(pathname), "%s/.forward", pw->pw_dir)) return 0; fp = fopen(pathname, "r"); diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c index d5af2d7fcd9..d204b993b14 100644 --- a/usr.sbin/smtpd/lka.c +++ b/usr.sbin/smtpd/lka.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka.c,v 1.24 2009/02/18 12:06:01 jacekm Exp $ */ +/* $OpenBSD: lka.c,v 1.25 2009/02/22 11:44:29 form Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -49,7 +49,7 @@ void lka_disable_events(struct smtpd *); int lka_verify_mail(struct smtpd *, struct path *); int lka_resolve_mail(struct smtpd *, struct rule *, struct path *); int lka_forward_file(struct passwd *); -int lka_expand(char *, size_t, struct path *); +size_t lka_expand(char *, size_t, struct path *); int aliases_exist(struct smtpd *, char *); int aliases_get(struct smtpd *, struct aliaseslist *, char *); int lka_resolve_alias(struct path *, struct alias *); @@ -320,7 +320,7 @@ lka_dispatch_smtp(int sig, short event, void *p) break; } - strlcpy(s->s_hostname, addr, MAXHOSTNAMELEN); + strlcpy(s->s_hostname, addr, sizeof(s->s_hostname)); imsg_compose(ibuf, IMSG_LKA_HOST, 0, 0, -1, s, sizeof(struct session)); break; @@ -640,7 +640,7 @@ lka_resolve_mail(struct smtpd *env, struct rule *rule, struct path *path) struct passwd *pw; char *p; - (void)strlcpy(username, path->user, MAXLOGNAME); + (void)strlcpy(username, path->user, sizeof(username)); for (p = &username[0]; *p != '\0' && *p != '+'; ++p) *p = tolower((int)*p); @@ -654,16 +654,18 @@ lka_resolve_mail(struct smtpd *env, struct rule *rule, struct path *path) pw = safe_getpwnam(username); if (pw == NULL) return 0; - (void)strlcpy(path->pw_name, pw->pw_name, MAXLOGNAME); - if (lka_expand(path->rule.r_value.path, MAXPATHLEN, path) >= - MAXPATHLEN) + (void)strlcpy(path->pw_name, pw->pw_name, + sizeof(path->pw_name)); + if (lka_expand(path->rule.r_value.path, + sizeof(path->rule.r_value.path), path) >= + sizeof(path->rule.r_value.path)) return 0; } return 1; } -int +size_t lka_expand(char *buf, size_t len, struct path *path) { char *p, *pbuf; @@ -694,9 +696,10 @@ lka_expand(char *buf, size_t len, struct path *path) char username[MAXLOGNAME]; char *delim; - ret = strlcpy(username, p + 1, MAXLOGNAME); + ret = strlcpy(username, p + 1, + sizeof(username)); delim = strchr(username, '/'); - if (delim == NULL && ret >= MAXLOGNAME) { + if (delim == NULL && ret >= sizeof(username)) { continue; } @@ -794,13 +797,15 @@ lka_resolve_alias(struct path *path, struct alias *alias) case ALIAS_FILENAME: log_debug("FILENAME: %s", alias->u.filename); path->rule.r_action = A_FILENAME; - strlcpy(path->u.filename, alias->u.filename, MAXPATHLEN); + strlcpy(path->u.filename, alias->u.filename, + sizeof(path->u.filename)); break; case ALIAS_FILTER: log_debug("FILTER: %s", alias->u.filter); path->rule.r_action = A_EXT; - strlcpy(path->rule.r_value.command, alias->u.filter + 2, MAXPATHLEN); + strlcpy(path->rule.r_value.command, alias->u.filter + 2, + sizeof(path->rule.r_value.command)); path->rule.r_value.command[strlen(path->rule.r_value.command) - 1] = '\0'; break; @@ -895,7 +900,7 @@ lka_resolve_path(struct smtpd *env, struct path *path) struct passwd *pw; char *p; - (void)strlcpy(username, path->user, MAXLOGNAME); + (void)strlcpy(username, path->user, sizeof(username)); for (p = &username[0]; *p != '\0' && *p != '+'; ++p) *p = tolower((int)*p); @@ -910,9 +915,11 @@ lka_resolve_path(struct smtpd *env, struct path *path) pw = safe_getpwnam(username); if (pw == NULL) return 0; - (void)strlcpy(path->pw_name, pw->pw_name, MAXLOGNAME); - if (lka_expand(path->rule.r_value.path, MAXPATHLEN, path) >= - MAXPATHLEN) + (void)strlcpy(path->pw_name, pw->pw_name, + sizeof(path->pw_name)); + if (lka_expand(path->rule.r_value.path, + sizeof(path->rule.r_value.path), path) >= + sizeof(path->rule.r_value.path)) return 0; } diff --git a/usr.sbin/smtpd/makemap.c b/usr.sbin/smtpd/makemap.c index 0d9a1c232a2..f18bfd13b84 100644 --- a/usr.sbin/smtpd/makemap.c +++ b/usr.sbin/smtpd/makemap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: makemap.c,v 1.10 2009/02/17 23:50:58 jacekm Exp $ */ +/* $OpenBSD: makemap.c,v 1.11 2009/02/22 11:44:29 form Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -133,7 +133,7 @@ main(int argc, char *argv[]) if (oflag == NULL && asprintf(&oflag, "%s.db", source) == -1) err(1, "asprintf"); - if (! bsnprintf(dbname, MAXPATHLEN, "%s.XXXXXXXXXXX", oflag)) + if (! bsnprintf(dbname, sizeof(dbname), "%s.XXXXXXXXXXX", oflag)) errx(1, "path too long"); if (mkstemp(dbname) == -1) err(1, "mkstemp"); diff --git a/usr.sbin/smtpd/mta.c b/usr.sbin/smtpd/mta.c index 786f038fe10..e3aa5afd6bb 100644 --- a/usr.sbin/smtpd/mta.c +++ b/usr.sbin/smtpd/mta.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mta.c,v 1.28 2009/02/20 15:27:01 pea Exp $ */ +/* $OpenBSD: mta.c,v 1.29 2009/02/22 11:44:29 form Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -264,8 +264,11 @@ mta_dispatch_runner(int sig, short event, void *p) fatalx("mta_dispatch_runner: internal inconsistency."); batchp->session_ss = messagep->session_ss; - strlcpy(batchp->session_hostname, messagep->session_hostname, MAXHOSTNAMELEN); - strlcpy(batchp->session_helo, messagep->session_helo, MAXHOSTNAMELEN); + strlcpy(batchp->session_hostname, + messagep->session_hostname, + sizeof(batchp->session_hostname)); + strlcpy(batchp->session_helo, messagep->session_helo, + sizeof(batchp->session_helo)); TAILQ_INSERT_TAIL(&batchp->messages, messagep, entry); @@ -476,7 +479,8 @@ mta_write(int s, short event, void *arg) bufferevent_free(sessionp->s_bev); sessionp->s_bev = NULL; } - strlcpy(batchp->errorline, "connection timed-out.", MAX_LINE_SIZE); + strlcpy(batchp->errorline, "connection timed-out.", + sizeof(batchp->errorline)); ret = 0; while (sessionp->mx_off < sessionp->mx_cnt && @@ -536,12 +540,12 @@ mta_reply_handler(struct bufferevent *bev, void *arg) log_debug("remote server sent: [%s]", line); - strlcpy(codebuf, line, sizeof codebuf); + strlcpy(codebuf, line, sizeof(codebuf)); code = strtonum(codebuf, 0, UINT16_MAX, &errstr); if (errstr || code < 100) { /* Server sent invalid line, protocol error */ batchp->status |= S_BATCH_PERMFAILURE; - strlcpy(batchp->errorline, line, MAX_LINE_SIZE); + strlcpy(batchp->errorline, line, sizeof(batchp->errorline)); mta_batch_update_queue(batchp); session_destroy(sessionp); return 0; @@ -597,7 +601,7 @@ mta_reply_handler(struct bufferevent *bev, void *arg) case 450: case 451: batchp->status |= S_BATCH_TEMPFAILURE; - strlcpy(batchp->errorline, line, MAX_LINE_SIZE); + strlcpy(batchp->errorline, line, sizeof(batchp->errorline)); mta_batch_update_queue(batchp); session_destroy(sessionp); return 0; @@ -609,7 +613,8 @@ mta_reply_handler(struct bufferevent *bev, void *arg) case 550: if (sessionp->s_state == S_RCPT) { batchp->messagep->status = (S_MESSAGE_REJECTED|S_MESSAGE_PERMFAILURE); - strlcpy(batchp->messagep->session_errorline, line, MAX_LINE_SIZE); + strlcpy(batchp->messagep->session_errorline, line, + sizeof(batchp->messagep->session_errorline)); break; } case 354: @@ -634,7 +639,7 @@ mta_reply_handler(struct bufferevent *bev, void *arg) log_debug("Ouch, SMTP session returned unhandled %d status.", code); batchp->status |= S_BATCH_PERMFAILURE; - strlcpy(batchp->errorline, line, MAX_LINE_SIZE); + strlcpy(batchp->errorline, line, sizeof(batchp->errorline)); mta_batch_update_queue(batchp); session_destroy(sessionp); return 0; diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y index 4c7df45705b..e738e7cc95a 100644 --- a/usr.sbin/smtpd/parse.y +++ b/usr.sbin/smtpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.24 2009/01/30 10:09:58 form Exp $ */ +/* $OpenBSD: parse.y,v 1.25 2009/02/22 11:44:29 form Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -482,7 +482,8 @@ mapref : STRING { free(m); YYERROR; } - if (! bsnprintf(m->m_name, MAX_LINE_SIZE, "<dynamic(%u)>", m->m_id)) + if (! bsnprintf(m->m_name, sizeof(m->m_name), + "<dynamic(%u)>", m->m_id)) fatal("snprintf"); m->m_flags |= F_DYNAMIC|F_USED; m->m_type = T_SINGLE; @@ -555,7 +556,8 @@ mapref : STRING { free(m); YYERROR; } - if (! bsnprintf(m->m_name, MAX_LINE_SIZE, "<dynamic(%u)>", m->m_id)) + if (! bsnprintf(m->m_name, sizeof(m->m_name), + "<dynamic(%u)>", m->m_id)) fatal("snprintf"); m->m_flags |= F_DYNAMIC|F_USED; m->m_type = T_LIST; @@ -580,7 +582,8 @@ mapref : STRING { free(m); YYERROR; } - if (! bsnprintf(m->m_name, MAX_LINE_SIZE, "<dynamic(%u)>", m->m_id)) + if (! bsnprintf(m->m_name, sizeof(m->m_name), + "<dynamic(%u)>", m->m_id)) fatal("snprintf"); m->m_flags |= F_DYNAMIC|F_USED; m->m_type = T_HASH; @@ -717,7 +720,8 @@ from : FROM mapref { free(m); YYERROR; } - if (! bsnprintf(m->m_name, MAX_LINE_SIZE, "<dynamic(%u)>", m->m_id)) + if (! bsnprintf(m->m_name, sizeof(m->m_name), + "<dynamic(%u)>", m->m_id)) fatal("snprintf"); m->m_flags |= F_DYNAMIC|F_USED; m->m_type = T_SINGLE; @@ -765,7 +769,8 @@ from : FROM mapref { free(m); YYERROR; } - if (! bsnprintf(m->m_name, MAX_LINE_SIZE, "<dynamic(%u)>", m->m_id)) + if (! bsnprintf(m->m_name, sizeof(m->m_name), + "<dynamic(%u)>", m->m_id)) fatal("snprintf"); m->m_flags |= F_DYNAMIC|F_USED; m->m_type = T_SINGLE; diff --git a/usr.sbin/smtpd/queue_shared.c b/usr.sbin/smtpd/queue_shared.c index b44d1aff89d..17d37c53b61 100644 --- a/usr.sbin/smtpd/queue_shared.c +++ b/usr.sbin/smtpd/queue_shared.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue_shared.c,v 1.9 2009/02/16 10:15:10 jacekm Exp $ */ +/* $OpenBSD: queue_shared.c,v 1.10 2009/02/22 11:44:29 form Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -61,7 +61,7 @@ queue_create_layout_message(char *queuepath, char *message_id) char rootdir[MAXPATHLEN]; char evpdir[MAXPATHLEN]; - if (! bsnprintf(rootdir, MAXPATHLEN, "%s/%d.XXXXXXXXXXXXXXXX", + if (! bsnprintf(rootdir, sizeof(rootdir), "%s/%d.XXXXXXXXXXXXXXXX", queuepath, time(NULL))) fatalx("queue_create_layout_message: snprintf"); @@ -78,7 +78,8 @@ queue_create_layout_message(char *queuepath, char *message_id) >= MAX_ID_SIZE) fatalx("queue_create_layout_message: truncation"); - if (! bsnprintf(evpdir, MAXPATHLEN, "%s%s", rootdir, PATH_ENVELOPES)) + if (! bsnprintf(evpdir, sizeof(evpdir), "%s%s", rootdir, + PATH_ENVELOPES)) fatalx("queue_create_layout_message: snprintf"); if (mkdir(evpdir, 0700) == -1) { @@ -99,10 +100,10 @@ queue_delete_layout_message(char *queuepath, char *msgid) char rootdir[MAXPATHLEN]; char purgedir[MAXPATHLEN]; - if (! bsnprintf(rootdir, MAXPATHLEN, "%s/%s", queuepath, msgid)) + if (! bsnprintf(rootdir, sizeof(rootdir), "%s/%s", queuepath, msgid)) fatalx("snprintf"); - if (! bsnprintf(purgedir, MAXPATHLEN, "%s/%s", PATH_PURGE, msgid)) + if (! bsnprintf(purgedir, sizeof(purgedir), "%s/%s", PATH_PURGE, msgid)) fatalx("snprintf"); if (rename(rootdir, purgedir) == -1) { @@ -121,7 +122,7 @@ queue_record_layout_envelope(char *queuepath, struct message *message) int fd; again: - if (! bsnprintf(evpname, MAXPATHLEN, "%s/%s%s/%s.%qu", queuepath, + if (! bsnprintf(evpname, sizeof(evpname), "%s/%s%s/%s.%qu", queuepath, message->message_id, PATH_ENVELOPES, message->message_id, (u_int64_t)arc4random())) fatalx("queue_record_incoming_envelope: snprintf"); @@ -140,8 +141,8 @@ again: fatal("queue_record_incoming_envelope: fdopen"); message->creation = time(NULL); - if (strlcpy(message->message_uid, strrchr(evpname, '/') + 1, MAX_ID_SIZE) - >= MAX_ID_SIZE) + if (strlcpy(message->message_uid, strrchr(evpname, '/') + 1, + sizeof(message->message_uid)) >= sizeof(message->message_uid)) fatalx("queue_record_incoming_envelope: truncation"); if (fwrite(message, sizeof (struct message), 1, fp) != 1) { @@ -169,7 +170,7 @@ queue_remove_layout_envelope(char *queuepath, struct message *message) { char pathname[MAXPATHLEN]; - if (! bsnprintf(pathname, MAXPATHLEN, "%s/%s%s/%s", queuepath, + if (! bsnprintf(pathname, sizeof(pathname), "%s/%s%s/%s", queuepath, message->message_id, PATH_ENVELOPES, message->message_uid)) fatal("queue_remove_incoming_envelope: snprintf"); @@ -185,11 +186,11 @@ queue_commit_layout_message(char *queuepath, struct message *messagep) char rootdir[MAXPATHLEN]; char queuedir[MAXPATHLEN]; - if (! bsnprintf(rootdir, MAXPATHLEN, "%s/%s", queuepath, + if (! bsnprintf(rootdir, sizeof(rootdir), "%s/%s", queuepath, messagep->message_id)) fatal("queue_commit_message_incoming: snprintf"); - if (! bsnprintf(queuedir, MAXPATHLEN, "%s/%d", PATH_QUEUE, + if (! bsnprintf(queuedir, sizeof(queuedir), "%s/%d", PATH_QUEUE, queue_hash(messagep->message_id))) fatal("queue_commit_message_incoming: snprintf"); @@ -200,8 +201,9 @@ queue_commit_layout_message(char *queuepath, struct message *messagep) fatal("queue_commit_message_incoming: mkdir"); } - if (strlcat(queuedir, "/", MAXPATHLEN) >= MAXPATHLEN || - strlcat(queuedir, messagep->message_id, MAXPATHLEN) >= MAXPATHLEN) + if (strlcat(queuedir, "/", sizeof(queuedir)) >= sizeof(queuedir) || + strlcat(queuedir, messagep->message_id, sizeof(queuedir)) >= + sizeof(queuedir)) fatalx("queue_commit_incoming_message: truncation"); if (rename(rootdir, queuedir) == -1) { @@ -218,7 +220,7 @@ queue_open_layout_messagefile(char *queuepath, struct message *messagep) { char pathname[MAXPATHLEN]; - if (! bsnprintf(pathname, MAXPATHLEN, "%s/%s/message", queuepath, + if (! bsnprintf(pathname, sizeof(pathname), "%s/%s/message", queuepath, messagep->message_id)) fatal("queue_open_incoming_message_file: snprintf"); @@ -307,8 +309,8 @@ queue_open_message_file(char *msgid) hval = queue_hash(msgid); - if (! bsnprintf(pathname, MAXPATHLEN, "%s/%d/%s/message", PATH_QUEUE, - hval, msgid)) + if (! bsnprintf(pathname, sizeof(pathname), "%s/%d/%s/message", + PATH_QUEUE, hval, msgid)) fatal("queue_open_message_file: snprintf"); if ((fd = open(pathname, O_RDONLY)) == -1) @@ -326,15 +328,15 @@ queue_delete_message(char *msgid) u_int16_t hval; hval = queue_hash(msgid); - if (! bsnprintf(rootdir, MAXPATHLEN, "%s/%d/%s", PATH_QUEUE, + if (! bsnprintf(rootdir, sizeof(rootdir), "%s/%d/%s", PATH_QUEUE, hval, msgid)) fatal("queue_delete_message: snprintf"); - if (! bsnprintf(evpdir, MAXPATHLEN, "%s%s", - rootdir, PATH_ENVELOPES)) + if (! bsnprintf(evpdir, sizeof(evpdir), "%s%s", rootdir, + PATH_ENVELOPES)) fatal("queue_delete_message: snprintf"); - if (! bsnprintf(msgpath, MAXPATHLEN, "%s/message", rootdir)) + if (! bsnprintf(msgpath, sizeof(msgpath), "%s/message", rootdir)) fatal("queue_delete_message: snprintf"); if (unlink(msgpath) == -1) @@ -352,8 +354,7 @@ queue_delete_message(char *msgid) if (rmdir(rootdir) == -1) fatal("#2 queue_delete_message: rmdir"); - if (! bsnprintf(rootdir, MAXPATHLEN, "%s/%d", PATH_QUEUE, - hval)) + if (! bsnprintf(rootdir, sizeof(rootdir), "%s/%d", PATH_QUEUE, hval)) fatal("queue_delete_message: snprintf"); rmdir(rootdir); @@ -402,15 +403,15 @@ queue_remove_envelope(struct message *messagep) hval = queue_hash(messagep->message_id); - if (! bsnprintf(pathname, MAXPATHLEN, "%s/%d/%s%s/%s", PATH_QUEUE, - hval, messagep->message_id, PATH_ENVELOPES, + if (! bsnprintf(pathname, sizeof(pathname), "%s/%d/%s%s/%s", + PATH_QUEUE, hval, messagep->message_id, PATH_ENVELOPES, messagep->message_uid)) fatal("queue_remove_envelope: snprintf"); if (unlink(pathname) == -1) fatal("queue_remove_envelope: unlink"); - if (! bsnprintf(pathname, MAXPATHLEN, "%s/%d/%s%s", PATH_QUEUE, + if (! bsnprintf(pathname, sizeof(pathname), "%s/%d/%s%s", PATH_QUEUE, hval, messagep->message_id, PATH_ENVELOPES)) fatal("queue_remove_envelope: snprintf"); @@ -427,10 +428,10 @@ queue_update_envelope(struct message *messagep) char dest[MAXPATHLEN]; FILE *fp; - if (! bsnprintf(temp, MAXPATHLEN, "%s/envelope.tmp", PATH_INCOMING)) + if (! bsnprintf(temp, sizeof(temp), "%s/envelope.tmp", PATH_INCOMING)) fatalx("queue_update_envelope"); - if (! bsnprintf(dest, MAXPATHLEN, "%s/%d/%s%s/%s", PATH_QUEUE, + if (! bsnprintf(dest, sizeof(dest), "%s/%d/%s%s/%s", PATH_QUEUE, queue_hash(messagep->message_id), messagep->message_id, PATH_ENVELOPES, messagep->message_uid)) fatal("queue_update_envelope: snprintf"); @@ -473,11 +474,11 @@ queue_load_envelope(struct message *messagep, char *evpid) char msgid[MAX_ID_SIZE]; FILE *fp; - if (strlcpy(msgid, evpid, MAX_ID_SIZE) >= MAX_ID_SIZE) + if (strlcpy(msgid, evpid, sizeof(msgid)) >= sizeof(msgid)) fatalx("queue_load_envelope: truncation"); *strrchr(msgid, '.') = '\0'; - if (! bsnprintf(pathname, MAXPATHLEN, "%s/%d/%s%s/%s", PATH_QUEUE, + if (! bsnprintf(pathname, sizeof(pathname), "%s/%d/%s%s/%s", PATH_QUEUE, queue_hash(msgid), msgid, PATH_ENVELOPES, evpid)) fatalx("queue_load_envelope: snprintf"); @@ -630,13 +631,13 @@ walk_queue(struct qwalk *q, char *fname) log_warnx("walk_queue: invalid bucket: %s", fname); return (QWALK_AGAIN); } - if (! bsnprintf(q->path, MAXPATHLEN, "%s/%d", PATH_QUEUE, + if (! bsnprintf(q->path, sizeof(q->path), "%s/%d", PATH_QUEUE, q->bucket)) fatalx("walk_queue: snprintf"); return (QWALK_RECURSE); case 1: - if (! bsnprintf(q->path, MAXPATHLEN, "%s/%d/%s%s", PATH_QUEUE, - q->bucket, fname, PATH_ENVELOPES)) + if (! bsnprintf(q->path, sizeof(q->path), "%s/%d/%s%s", + PATH_QUEUE, q->bucket, fname, PATH_ENVELOPES)) fatalx("walk_queue: snprintf"); return (QWALK_RECURSE); case 2: diff --git a/usr.sbin/smtpd/runner.c b/usr.sbin/smtpd/runner.c index e0b41d86c21..a4a24110aa8 100644 --- a/usr.sbin/smtpd/runner.c +++ b/usr.sbin/smtpd/runner.c @@ -1,4 +1,4 @@ -/* $OpenBSD: runner.c,v 1.30 2009/02/15 10:32:23 jacekm Exp $ */ +/* $OpenBSD: runner.c,v 1.31 2009/02/22 11:44:29 form Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -781,13 +781,14 @@ runner_purge_message(char *msgid) DIR *dirp; struct dirent *dp; - if (! bsnprintf(rootdir, MAXPATHLEN, "%s/%s", PATH_PURGE, msgid)) + if (! bsnprintf(rootdir, sizeof(rootdir), "%s/%s", PATH_PURGE, msgid)) fatal("queue_delete_incoming_message: snprintf"); - if (! bsnprintf(evpdir, MAXPATHLEN, "%s%s", rootdir, PATH_ENVELOPES)) + if (! bsnprintf(evpdir, sizeof(evpdir), "%s%s", rootdir, + PATH_ENVELOPES)) fatal("queue_delete_incoming_message: snprintf"); - if (! bsnprintf(msgpath, MAXPATHLEN, "%s/message", rootdir)) + if (! bsnprintf(msgpath, sizeof(msgpath), "%s/message", rootdir)) fatal("queue_delete_incoming_message: snprintf"); if (unlink(msgpath) == -1) @@ -804,7 +805,7 @@ runner_purge_message(char *msgid) if (strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0) continue; - if (! bsnprintf(evppath, MAXPATHLEN, "%s/%s", evpdir, + if (! bsnprintf(evppath, sizeof(evppath), "%s/%s", evpdir, dp->d_name)) fatal("queue_delete_incoming_message: snprintf"); diff --git a/usr.sbin/smtpd/smtp.c b/usr.sbin/smtpd/smtp.c index d4feaff556b..dcd329185ad 100644 --- a/usr.sbin/smtpd/smtp.c +++ b/usr.sbin/smtpd/smtp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtp.c,v 1.26 2009/02/18 00:29:52 gilles Exp $ */ +/* $OpenBSD: smtp.c,v 1.27 2009/02/22 11:44:29 form Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -317,9 +317,10 @@ smtp_dispatch_lka(int sig, short event, void *p) if (s == NULL) fatal("smtp_dispatch_lka: session is gone"); - strlcpy(s->s_hostname, ss->s_hostname, MAXHOSTNAMELEN); + strlcpy(s->s_hostname, ss->s_hostname, + sizeof(s->s_hostname)); strlcpy(s->s_msg.session_hostname, ss->s_hostname, - MAXHOSTNAMELEN); + sizeof(s->s_msg.session_hostname)); session_init(s->s_l, s); @@ -723,8 +724,9 @@ smtp_accept(int fd, short event, void *p) if (s_smtp.sessions_active == s->s_env->sc_maxconn) event_del(&l->ev); - strlcpy(s->s_hostname, "<unknown>", MAXHOSTNAMELEN); - strlcpy(s->s_msg.session_hostname, s->s_hostname, MAXHOSTNAMELEN); + strlcpy(s->s_hostname, "<unknown>", sizeof(s->s_hostname)); + strlcpy(s->s_msg.session_hostname, s->s_hostname, + sizeof(s->s_msg.session_hostname)); imsg_compose(s->s_env->sc_ibufs[PROC_LKA], IMSG_LKA_HOST, 0, 0, -1, s, sizeof(struct session)); diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c index a485d1eb846..d3c8f253b4c 100644 --- a/usr.sbin/smtpd/smtpd.c +++ b/usr.sbin/smtpd/smtpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.c,v 1.30 2009/02/15 10:32:23 jacekm Exp $ */ +/* $OpenBSD: smtpd.c,v 1.31 2009/02/22 11:44:29 form Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -760,7 +760,7 @@ setup_spool(uid_t uid, gid_t gid) struct stat sb; int ret; - if (! bsnprintf(pathname, MAXPATHLEN, "%s", PATH_SPOOL)) + if (! bsnprintf(pathname, sizeof(pathname), "%s", PATH_SPOOL)) fatal("snprintf"); if (stat(pathname, &sb) == -1) { @@ -805,7 +805,7 @@ setup_spool(uid_t uid, gid_t gid) ret = 1; for (n = 0; n < sizeof(paths)/sizeof(paths[0]); n++) { - if (! bsnprintf(pathname, MAXPATHLEN, "%s%s", PATH_SPOOL, + if (! bsnprintf(pathname, sizeof(pathname), "%s%s", PATH_SPOOL, paths[n])) fatal("snprintf"); @@ -885,7 +885,7 @@ parent_open_message_file(struct batch *batchp) messagep = &batchp->message; hval = queue_hash(messagep->message_id); - if (! bsnprintf(pathname, MAXPATHLEN, "%s%s/%d/%s/message", + if (! bsnprintf(pathname, sizeof(pathname), "%s%s/%d/%s/message", PATH_SPOOL, PATH_QUEUE, hval, batchp->message_id)) { batchp->message.status |= S_MESSAGE_PERMFAILURE; return -1; @@ -933,7 +933,8 @@ parent_mailbox_open(struct passwd *pw, struct batch *batchp, struct path *path) char pathname[MAXPATHLEN]; int mode = O_CREAT|O_APPEND|O_RDWR|O_SYNC|O_NONBLOCK; - if (! bsnprintf(pathname, MAXPATHLEN, "%s", path->rule.r_value.path)) + if (! bsnprintf(pathname, sizeof(pathname), "%s", + path->rule.r_value.path)) return -1; if (! parent_mailbox_init(pw, pathname)) { @@ -990,7 +991,8 @@ parent_maildir_init(struct passwd *pw, char *root) char *subdir[] = { "/", "/tmp", "/cur", "/new" }; for (i = 0; i < sizeof (subdir) / sizeof (char *); ++i) { - if (! bsnprintf(pathname, MAXPATHLEN, "%s%s", root, subdir[i])) + if (! bsnprintf(pathname, sizeof(pathname), "%s%s", root, + subdir[i])) return 0; if (mkdir(pathname, 0700) == -1) if (errno != EEXIST) @@ -1008,7 +1010,8 @@ parent_maildir_open(struct passwd *pw, struct batch *batchp, struct path *path) char pathname[MAXPATHLEN]; int mode = O_CREAT|O_RDWR|O_TRUNC|O_SYNC; - if (! bsnprintf(pathname, MAXPATHLEN, "%s", path->rule.r_value.path)) + if (! bsnprintf(pathname, sizeof(pathname), "%s", + path->rule.r_value.path)) return -1; if (! parent_maildir_init(pw, pathname)) { @@ -1016,7 +1019,7 @@ parent_maildir_open(struct passwd *pw, struct batch *batchp, struct path *path) return -1; } - if (! bsnprintf(pathname, MAXPATHLEN, "%s/tmp/%s", + if (! bsnprintf(pathname, sizeof(pathname), "%s/tmp/%s", pathname, batchp->message.message_uid)) { batchp->message.status |= S_MESSAGE_TEMPFAILURE; return -1; @@ -1039,9 +1042,9 @@ parent_mailfile_rename(struct batch *batchp, struct path *path) char srcpath[MAXPATHLEN]; char dstpath[MAXPATHLEN]; - if (! bsnprintf(srcpath, MAXPATHLEN, "%s/tmp/%s", + if (! bsnprintf(srcpath, sizeof(srcpath), "%s/tmp/%s", path->rule.r_value.path, batchp->message.message_uid) || - ! bsnprintf(dstpath, MAXPATHLEN, "%s/new/%s", + ! bsnprintf(dstpath, sizeof(dstpath), "%s/new/%s", path->rule.r_value.path, batchp->message.message_uid)) return 0; @@ -1122,7 +1125,7 @@ parent_filename_open(struct passwd *pw, struct batch *batchp, struct path *path) char pathname[MAXPATHLEN]; int mode = O_CREAT|O_APPEND|O_RDWR|O_SYNC|O_NONBLOCK; - if (! bsnprintf(pathname, MAXPATHLEN, "%s", path->u.filename)) + if (! bsnprintf(pathname, sizeof(pathname), "%s", path->u.filename)) return -1; fd = open(pathname, mode, 0600); diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c index 687b3267fca..9fdb28cfed7 100644 --- a/usr.sbin/smtpd/util.c +++ b/usr.sbin/smtpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.11 2009/02/18 22:39:12 jacekm Exp $ */ +/* $OpenBSD: util.c,v 1.12 2009/02/22 11:44:29 form Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -137,11 +137,11 @@ recipient_to_path(struct path *path, char *recipient) } if (strlcpy(path->user, username, sizeof(path->user)) - >= MAX_LOCALPART_SIZE) + >= sizeof(path->user)) return 0; if (strlcpy(path->domain, hostname, sizeof(path->domain)) - >= MAX_DOMAINPART_SIZE) + >= sizeof(path->domain)) return 0; return 1; |