-/* $OpenBSD: mfa_session.c,v 1.21 2014/04/04 16:10:42 eric Exp $ */
+/* $OpenBSD: mfa_session.c,v 1.22 2014/04/19 13:18:14 gilles Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@poolp.org>
memmove(&q->u.connect.local, local, local->sa_len);
memmove(&q->u.connect.remote, remote, remote->sa_len);
- strlcpy(q->u.connect.hostname, host, sizeof(q->u.connect.hostname));
+ if (strlcpy(q->u.connect.hostname, host,
+ sizeof(q->u.connect.hostname)) >=
+ sizeof(q->u.connect.hostname))
+ fatalx("hostname too large");
q->smtp.status = MFA_OK;
q->smtp.code = 0;
s = tree_xget(&sessions, id);
q = mfa_query(s, QT_QUERY, hook);
- strlcpy(q->u.maddr.user, maddr->user, sizeof(q->u.maddr.user));
- strlcpy(q->u.maddr.domain, maddr->domain, sizeof(q->u.maddr.domain));
+ if (strlcpy(q->u.maddr.user, maddr->user, sizeof(q->u.maddr.user))
+ >= sizeof(q.u.maddr.user))
+ fatalx("username too large");
+ if (strlcpy(q->u.maddr.domain, maddr->domain, sizeof(q->u.maddr.domain))
+ >= sizeof(q.u.maddr.domain))
+ fatalx("hostname too large");
mfa_drain_query(q);
}
s = tree_xget(&sessions, id);
q = mfa_query(s, QT_QUERY, hook);
- strlcpy(q->u.line, line, sizeof(q->u.line));
+ if (strlcpy(q->u.line, line, sizeof(q->u.line))
+ >= sizeof(q->u.line))
+ fatalx("line too large");
mfa_drain_query(q);
}
{
static char buf[1024];
char tmp[1024];
+ int ret;
tmp[0] = '\0';
switch(q->hook) {
case HOOK_CONNECT:
- strlcat(tmp, "=", sizeof tmp);
- strlcat(tmp, ss_to_text(&q->u.connect.local), sizeof tmp);
- strlcat(tmp, " <-> ", sizeof tmp);
- strlcat(tmp, ss_to_text(&q->u.connect.remote), sizeof tmp);
- strlcat(tmp, "(", sizeof tmp);
- strlcat(tmp, q->u.connect.hostname, sizeof tmp);
- strlcat(tmp, ")", sizeof tmp);
+ (void)strlcat(tmp, "=", sizeof tmp);
+ (void)strlcat(tmp, ss_to_text(&q->u.connect.local), sizeof tmp);
+ (void)strlcat(tmp, " <-> ", sizeof tmp);
+ (void)strlcat(tmp, ss_to_text(&q->u.connect.remote), sizeof tmp);
+ (void)strlcat(tmp, "(", sizeof tmp);
+ (void)strlcat(tmp, q->u.connect.hostname, sizeof tmp);
+ if (strlcat(tmp, ")", sizeof tmp) >= sizeof tmp)
+ fatalx("line too large");
break;
case HOOK_MAIL:
case HOOK_RCPT:
- snprintf(tmp, sizeof tmp, "=%s@%s",
+ ret = snprintf(tmp, sizeof tmp, "=%s@%s",
q->u.maddr.user, q->u.maddr.domain);
+ if (ret == -1 || ret >= sizeof tmp)
+ fatalx("line too large");
break;
case HOOK_HELO:
- snprintf(tmp, sizeof tmp, "=%s", q->u.line);
+ ret = snprintf(tmp, sizeof tmp, "=%s", q->u.line);
+ if (ret == -1 || ret >= sizeof tmp)
+ fatalx("line too large");
break;
default:
break;
}
- snprintf(buf, sizeof buf, "%016"PRIx64"[%s,%s%s]",
+ ret = snprintf(buf, sizeof buf, "%016"PRIx64"[%s,%s%s]",
q->qid, type_to_str(q->type), hook_to_str(q->hook), tmp);
-
+ if (ret == -1 || ret >= sizeof buf)
+ fatalx("line too large");
return (buf);
}
mfa_filter_to_text(struct mfa_filter *f)
{
static char buf[1024];
+ int ret;
- snprintf(buf, sizeof buf, "filter:%s", mfa_filterproc_to_text(f->proc));
+ ret = snprintf(buf, sizeof buf, "filter:%s", mfa_filterproc_to_text(f->proc));
+ if (ret == -1 || ret >= sizeof buf)
+ fatalx("line too large");
return (buf);
}
mfa_filterproc_to_text(struct mfa_filterproc *proc)
{
static char buf[1024];
+ int ret;
- snprintf(buf, sizeof buf, "%s[hooks=0x%08x,flags=0x%04x]",
+ ret = snprintf(buf, sizeof buf, "%s[hooks=0x%08x,flags=0x%04x]",
proc->mproc.name, proc->hooks, proc->flags);
+ if (ret == -1 || ret >= sizeof buf)
+ fatalx("line too large");
return (buf);
}