From owner-svn-src-stable@freebsd.org Sun May 10 14:46:47 2020 Return-Path: Delivered-To: svn-src-stable@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 851B22E93E0; Sun, 10 May 2020 14:46:47 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49Kn2b30GMz4Gk7; Sun, 10 May 2020 14:46:47 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 620516D25; Sun, 10 May 2020 14:46:47 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 04AEklcu098006; Sun, 10 May 2020 14:46:47 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 04AEkle7098005; Sun, 10 May 2020 14:46:47 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <202005101446.04AEkle7098005@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: glebius set sender to glebius@FreeBSD.org using -f From: Gleb Smirnoff Date: Sun, 10 May 2020 14:46:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r360873 - stable/12/contrib/bsnmp/snmpd X-SVN-Group: stable-12 X-SVN-Commit-Author: glebius X-SVN-Commit-Paths: stable/12/contrib/bsnmp/snmpd X-SVN-Commit-Revision: 360873 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 May 2020 14:46:47 -0000 Author: glebius Date: Sun May 10 14:46:46 2020 New Revision: 360873 URL: https://svnweb.freebsd.org/changeset/base/360873 Log: Merge r360138: Fix immediate crash when snmpd is bound to a specific IP address. The code that sets up msghdr must first fully fill in the msghdr itself, and only then use CMSG_xxx() macros. PR: 246323 Modified: stable/12/contrib/bsnmp/snmpd/trans_inet.c Directory Properties: stable/12/ (props changed) Modified: stable/12/contrib/bsnmp/snmpd/trans_inet.c ============================================================================== --- stable/12/contrib/bsnmp/snmpd/trans_inet.c Sun May 10 14:09:30 2020 (r360872) +++ stable/12/contrib/bsnmp/snmpd/trans_inet.c Sun May 10 14:46:46 2020 (r360873) @@ -71,7 +71,7 @@ typedef void input_func(int, void *); typedef int activate_func(struct inet_port *); typedef void deactivate_func(struct inet_port *); typedef void parse_ctrl_func(struct port_sock *, const struct msghdr *); -typedef void setsrc_func(struct port_sock *, struct msghdr *); +typedef void setsrc_func(struct port_sock *, struct msghdr *, char *); static create_func ipv4_create; static input_func ipv4_input; @@ -401,13 +401,12 @@ inet_send2(struct tport *tp, const u_char *buf, size_t msg.msg_name = (void *)pi->peer; msg.msg_namelen = pi->peerlen; - msg.msg_control = NULL; - msg.msg_controllen = 0; - char cbuf[XMIT_CBUF_SIZE]; if (s->set_ret_source) { - msg.msg_control = cbuf; - s->setsrc(s, &msg); + s->setsrc(s, &msg, cbuf); + } else { + msg.msg_control = NULL; + msg.msg_controllen = 0; } return (sendmsg(s->input.fd, &msg, 0)); @@ -638,18 +637,20 @@ ipv4_parse_ctrl(struct port_sock *sock, const struct m * \param msg message */ static void -ipv4_setsrc(struct port_sock *sock, struct msghdr *msg) +ipv4_setsrc(struct port_sock *sock, struct msghdr *msg, char *cbuf) { - struct cmsghdr *cmsg = CMSG_FIRSTHDR(msg); + struct cmsghdr *cmsg; + msg->msg_control = cbuf; + msg->msg_controllen = CMSG_SPACE(sizeof(struct in_addr)); + /* select outgoing interface by setting source address */ + cmsg = CMSG_FIRSTHDR(msg); cmsg->cmsg_level = IPPROTO_IP; cmsg->cmsg_type = IP_SENDSRCADDR; cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_addr)); memcpy(CMSG_DATA(cmsg), &sock->ret_source.a4, sizeof(struct in_addr)); - - msg->msg_controllen = CMSG_SPACE(sizeof(struct in_addr)); } /** @@ -877,18 +878,20 @@ ipv6_parse_ctrl(struct port_sock *sock, const struct m * \param msg message */ static void -ipv6_setsrc(struct port_sock *sock, struct msghdr *msg) +ipv6_setsrc(struct port_sock *sock, struct msghdr *msg, char *cbuf) { - struct cmsghdr *cmsg = CMSG_FIRSTHDR(msg); + struct cmsghdr *cmsg; + msg->msg_control = cbuf; + msg->msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo)); + /* select outgoing interface by setting source address */ + cmsg = CMSG_FIRSTHDR(msg); cmsg->cmsg_level = IPPROTO_IPV6; cmsg->cmsg_type = IPV6_PKTINFO; cmsg->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo)); memcpy(CMSG_DATA(cmsg), &sock->ret_source.a6, sizeof(struct in6_pktinfo)); - - msg->msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo)); } /**