From 195c91bb2d9ff7af8faf59accb54a6bd7909f26c Mon Sep 17 00:00:00 2001 From: claudio Date: Mon, 3 May 2021 13:18:06 +0000 Subject: [PATCH] Like in the session engine do not inline the addr2sa call into connect and bind. The len argument is modified by addr2sa but is also used as argument in the call and it is undefined if the value of len in connect is set to the value "returned" by addr2sa(). Should fix connect issues seen on Linux system. OK denis@ --- usr.sbin/bgpd/bgpd.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c index e6bf4c88d49..72233aa88f4 100644 --- a/usr.sbin/bgpd/bgpd.c +++ b/usr.sbin/bgpd/bgpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.c,v 1.234 2021/02/16 08:29:16 claudio Exp $ */ +/* $OpenBSD: bgpd.c,v 1.235 2021/05/03 13:18:06 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -1261,6 +1261,7 @@ imsg_send_sockets(struct imsgbuf *se, struct imsgbuf *rde, struct imsgbuf *roa) void bgpd_rtr_connect(struct rtr_config *r) { + struct sockaddr *sa; socklen_t len; int fd; @@ -1270,8 +1271,8 @@ bgpd_rtr_connect(struct rtr_config *r) log_warn("rtr %s", r->descr); return; } - if (r->local_addr.aid != AID_UNSPEC) { - if (bind(fd, addr2sa(&r->local_addr, 0, &len), len) == -1) { + if ((sa = addr2sa(&r->local_addr, 0, &len)) != NULL) { + if (bind(fd, sa, len) == -1) { log_warn("rtr %s: bind to %s", r->descr, log_addr(&r->local_addr)); close(fd); @@ -1279,8 +1280,8 @@ bgpd_rtr_connect(struct rtr_config *r) } } - if (connect(fd, addr2sa(&r->remote_addr, r->remote_port, &len), len) == - -1) { + sa = addr2sa(&r->remote_addr, r->remote_port, &len); + if (connect(fd, sa, len) == -1) { log_warn("rtr %s: connect to %s:%u", r->descr, log_addr(&r->remote_addr), r->remote_port); close(fd); -- 2.20.1