diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2020-05-21 15:38:06 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2020-05-21 15:38:06 +0000 |
commit | 0d92399ef2ac3b828f87916994b1f0a7b5d2b3b2 (patch) | |
tree | ca7f0a2d6a01837fe2c4c9061d1ece90bc87f2e4 /usr.sbin | |
parent | 843e6dd5fa87791c0c1cf5cdbb023b20fc84c50a (diff) |
Correct getsockname(2)/getpeername(2) usage.
Fixes an uninitialized variable and a potential stack overflow
with IPv6 connections. From Leah Neukirchen; OK eric@ deraadt@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/smtpd/mta_session.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/usr.sbin/smtpd/mta_session.c b/usr.sbin/smtpd/mta_session.c index fa7c7e1ce0d..d384692a0e4 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.135 2020/04/24 11:34:07 eric Exp $ */ +/* $OpenBSD: mta_session.c,v 1.136 2020/05/21 15:38:05 millert Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -1809,21 +1809,25 @@ mta_filter_end(struct mta_session *s) static void mta_connected(struct mta_session *s) { - struct sockaddr sa_src; - struct sockaddr sa_dest; + struct sockaddr_storage sa_src; + struct sockaddr_storage sa_dest; int sa_len; log_info("%016"PRIx64" mta connected", s->id); - if (getsockname(io_fileno(s->io), &sa_src, &sa_len) == -1) + sa_len = sizeof sa_src; + if (getsockname(io_fileno(s->io), + (struct sockaddr *)&sa_src, &sa_len) == -1) bzero(&sa_src, sizeof sa_src); - if (getpeername(io_fileno(s->io), &sa_dest, &sa_len) == -1) + sa_len = sizeof sa_dest; + if (getpeername(io_fileno(s->io), + (struct sockaddr *)&sa_dest, &sa_len) == -1) bzero(&sa_dest, sizeof sa_dest); mta_report_link_connect(s, s->route->dst->ptrname, 1, - (struct sockaddr_storage *)&sa_src, - (struct sockaddr_storage *)&sa_dest); + &sa_src, + &sa_dest); } static void |