From owner-svn-src-all@freebsd.org Wed Dec 2 16:46:47 2020 Return-Path: Delivered-To: svn-src-all@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 09E0847F6C3; Wed, 2 Dec 2020 16:46:47 +0000 (UTC) (envelope-from markj@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 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 4CmPxy6vFyz3H0S; Wed, 2 Dec 2020 16:46:46 +0000 (UTC) (envelope-from markj@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 DF9322AA0; Wed, 2 Dec 2020 16:46:46 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0B2Gkk4a094540; Wed, 2 Dec 2020 16:46:46 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0B2Gkjkn094535; Wed, 2 Dec 2020 16:46:46 GMT (envelope-from markj@FreeBSD.org) Message-Id: <202012021646.0B2Gkjkn094535@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Wed, 2 Dec 2020 16:46:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r368278 - head/usr.sbin/rtsold X-SVN-Group: head X-SVN-Commit-Author: markj X-SVN-Commit-Paths: head/usr.sbin/rtsold X-SVN-Commit-Revision: 368278 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Dec 2020 16:46:47 -0000 Author: markj Date: Wed Dec 2 16:46:45 2020 New Revision: 368278 URL: https://svnweb.freebsd.org/changeset/base/368278 Log: rtsold: Fix bugs reported by Coverity - Avoid leaking a socket if llflags_get() fails. - Avoid leaking a file handle if rtsold_init_dumpfile() fails. - Tighten the check in if_nametosdl() which determines whether we failed to find the specified interface. - Fix errno handling in an error path in rtsock_open(). MFC after: 1 week Modified: head/usr.sbin/rtsold/cap_llflags.c head/usr.sbin/rtsold/dump.c head/usr.sbin/rtsold/if.c head/usr.sbin/rtsold/rtsock.c Modified: head/usr.sbin/rtsold/cap_llflags.c ============================================================================== --- head/usr.sbin/rtsold/cap_llflags.c Wed Dec 2 16:33:23 2020 (r368277) +++ head/usr.sbin/rtsold/cap_llflags.c Wed Dec 2 16:46:45 2020 (r368278) @@ -72,9 +72,12 @@ llflags_get(const char *ifname, int *flagsp) if (s < 0) return (-1); - if (getifaddrs(&ifap) != 0) - return (-1); - error = -1; + ifap = NULL; + if (getifaddrs(&ifap) != 0) { + error = errno; + goto out; + } + error = ENOENT; for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { if (strcmp(ifa->ifa_name, ifname) != 0) continue; @@ -88,27 +91,29 @@ llflags_get(const char *ifname, int *flagsp) memset(&ifr6, 0, sizeof(ifr6)); if (strlcpy(ifr6.ifr_name, ifname, sizeof(ifr6.ifr_name)) >= sizeof(ifr6.ifr_name)) { - freeifaddrs(ifap); - errno = EINVAL; - return (-1); + error = errno; + goto out; } memcpy(&ifr6.ifr_ifru.ifru_addr, sin6, sin6->sin6_len); if (ioctl(s, SIOCGIFAFLAG_IN6, &ifr6) < 0) { error = errno; - freeifaddrs(ifap); - errno = error; - return (-1); + goto out; } *flagsp = ifr6.ifr_ifru.ifru_flags6; error = 0; break; } +out: (void)close(s); - freeifaddrs(ifap); - if (error == -1) - errno = ENOENT; - return (error); + if (ifap != NULL) + freeifaddrs(ifap); + if (error != 0) { + errno = error; + return (-1); + } else { + return (0); + } } int Modified: head/usr.sbin/rtsold/dump.c ============================================================================== --- head/usr.sbin/rtsold/dump.c Wed Dec 2 16:33:23 2020 (r368277) +++ head/usr.sbin/rtsold/dump.c Wed Dec 2 16:46:45 2020 (r368278) @@ -148,6 +148,7 @@ rtsold_init_dumpfile(const char *dumpfile) if (caph_rights_limit(fileno(fp), &rights) != 0) { warnmsg(LOG_WARNING, __func__, "caph_rights_limit(%s): %s", dumpfile, strerror(errno)); + (void)fclose(fp); return (NULL); } return (fp); Modified: head/usr.sbin/rtsold/if.c ============================================================================== --- head/usr.sbin/rtsold/if.c Wed Dec 2 16:33:23 2020 (r368277) +++ head/usr.sbin/rtsold/if.c Wed Dec 2 16:46:45 2020 (r368278) @@ -327,7 +327,7 @@ if_nametosdl(char *name) } } } - if (next == lim) { + if (next >= lim) { /* search failed */ free(buf); return (NULL); Modified: head/usr.sbin/rtsold/rtsock.c ============================================================================== --- head/usr.sbin/rtsold/rtsock.c Wed Dec 2 16:33:23 2020 (r368277) +++ head/usr.sbin/rtsold/rtsock.c Wed Dec 2 16:46:45 2020 (r368278) @@ -84,7 +84,7 @@ rtsock_open(void) if (caph_rights_limit(s, &rights) != 0) { error = errno; (void)close(s); - errno = errno; + errno = error; return (-1); } return (s);