From patchwork Sun Aug 4 23:25:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 791 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director10.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id QDOiHH/2R13tZgAAIUCqbw for ; Mon, 05 Aug 2019 05:27:27 -0400 Received: from proxy6.mail.ord1d.rsapps.net ([172.30.191.6]) by director10.mail.ord1d.rsapps.net with LMTP id mIxuHH/2R12mVgAApN4f7A ; Mon, 05 Aug 2019 05:27:27 -0400 Received: from smtp7.gate.ord1c ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy6.mail.ord1d.rsapps.net with LMTP id EFdKHH/2R13XZgAAQyIf0w ; Mon, 05 Aug 2019 05:27:27 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp7.gate.ord1c.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dmarc=none (p=nil; dis=none) header.from=unstable.cc X-Suspicious-Flag: YES X-Classification-ID: 3d185202-b763-11e9-8ff9-bc305bf04148-1-1 Received: from [216.105.38.7] ([216.105.38.7:33958] helo=lists.sourceforge.net) by smtp7.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 50/F7-05825-F76F74D5; Mon, 05 Aug 2019 05:27:27 -0400 Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1huZFp-0008RL-1I; Mon, 05 Aug 2019 09:26:09 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1huZFn-0008RC-Ee for openvpn-devel@lists.sourceforge.net; Mon, 05 Aug 2019 09:26:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=WX+Ica3im9VMI6c0E7VWmoYvPRWScm57DyAItiEYJFo=; b=bYyLBHJ3aUa/jzJTt1TjpmUjNP 6EmOMx+NjBJxs/BaqH/spIEJKJ4S/1Okd905mIz8U7exCZ62nirp6LrHYvycoaRt+F4cWSaOu4ULx AiUv2rZimVe3PJpdIdfEtgPOdcyQIdbGVudLG8xW0BSiuYq7OQtAFPO1X8yKRrEeyAow=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=WX+Ica3im9VMI6c0E7VWmoYvPRWScm57DyAItiEYJFo=; b=eI0XdlmSCBDh4ipoJ1763nCnvL FFZ6tUvAv/XlmmkJ2m6p4ALpZxMmBYLxD7BdEKBZXcsq4mENlrxduXJGiyglelOJlATk7C6t7BGsC 5TKsnt46+x8/Nyr0HTWEOICeN39GoPD5J9KF9WyJ4AQ9VArKiRYWlDI2hEA1QOWawVJM=; Received: from s2.neomailbox.net ([5.148.176.60]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) id 1huZFl-00BSdI-40 for openvpn-devel@lists.sourceforge.net; Mon, 05 Aug 2019 09:26:07 +0000 From: Antonio Quartulli To: openvpn-devel@lists.sourceforge.net Date: Mon, 5 Aug 2019 11:25:24 +0200 Message-Id: <20190805092529.9467-2-a@unstable.cc> In-Reply-To: <20190805092529.9467-1-a@unstable.cc> References: <20190805092529.9467-1-a@unstable.cc> MIME-Version: 1.0 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [5.148.176.60 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1huZFl-00BSdI-40 Subject: [Openvpn-devel] [PATCH 1/6] sitnl: harden strncpy() by forcing arguments to have the same length X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Antonio Quartulli Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox From: Antonio Quartulli At the moment a strcpy() (without length check!) is performed between a string long IFNAMSIZ bytes and one of 16 bytes. This is ok right now because IFNAMSIZ is defined as 16, however this bit is not under our control and may change in he future without us being warned. For this reason, force both strings to use IFNAMSIZ as size and, since this constant may not exist on every platform, ensure it is always defined. Signed-off-by: Antonio Quartulli Acked-by: Gert Doering --- src/openvpn/networking_sitnl.c | 2 +- src/openvpn/route.h | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/openvpn/networking_sitnl.c b/src/openvpn/networking_sitnl.c index 4e29d8ba..ea730ec7 100644 --- a/src/openvpn/networking_sitnl.c +++ b/src/openvpn/networking_sitnl.c @@ -494,7 +494,7 @@ sitnl_route_best_gw(sa_family_t af_family, const inet_address_t *dst, /* save result in output variables */ memcpy(best_gw, &res.gw, res.addr_size); - strcpy(best_iface, res.iface); + strncpy(best_iface, res.iface, IFNAMSIZ); err: return ret; diff --git a/src/openvpn/route.h b/src/openvpn/route.h index 31d38e36..2e68091c 100644 --- a/src/openvpn/route.h +++ b/src/openvpn/route.h @@ -184,7 +184,11 @@ struct route_ipv6_gateway_info { #ifdef _WIN32 DWORD adapter_index; /* interface or ~0 if undefined */ #else - char iface[16]; /* interface name (null terminated), may be empty */ + /* non linux platform don't have this constant defined */ +#ifndef IFNAMSIZ +#define IFNAMSIZ 16 +#endif + char iface[IFNAMSIZ]; /* interface name (null terminated), may be empty */ #endif /* gateway interface hardware address */