From patchwork Sun Mar 21 20:43:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristof Provost via Openvpn-devel X-Patchwork-Id: 1647 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director12.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id GPZ2FghLWGALOwAAIUCqbw (envelope-from ) for ; Mon, 22 Mar 2021 03:45:12 -0400 Received: from proxy6.mail.iad3b.rsapps.net ([172.31.255.6]) by director12.mail.ord1d.rsapps.net with LMTP id eKZXFghLWGDHXgAAIasKDg (envelope-from ) for ; Mon, 22 Mar 2021 03:45:12 -0400 Received: from smtp12.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy6.mail.iad3b.rsapps.net with LMTPS id qB3PEAhLWGAGfwAARawThA (envelope-from ) for ; Mon, 22 Mar 2021 03:45:12 -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: smtp12.gate.iad3b.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=pass header.d=lists.sourceforge.net; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (signature verification failed) header.d=rozman.si; dmarc=pass (p=none; dis=none) header.from=lists.sourceforge.net X-Suspicious-Flag: NO X-Classification-ID: 87d44324-8ae2-11eb-9da3-525400ae1f9d-1-1 Received: from [216.105.38.7] ([216.105.38.7:55378] helo=lists.sourceforge.net) by smtp12.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 20/3E-29454-70B48506; Mon, 22 Mar 2021 03:45:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: Reply-To:From:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Subject:MIME-Version:References:In-Reply-To: Message-Id:Date:To:Sender:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=vldVF3kzEjHE/0LZDbWiq1+TEy1KgRwo/mhT95OTjY0=; b=Te/Cyd508OJSuIVJu4gthuUmG EOG9u0yIYPBoizAz9SeZj47Fjdn41HCVRA2QqW7aOPSIU4xxthJtEvpJ7KCnT87JhDOaHW5+8IZ6o ssqoQqgP8m06swudxVv+SD5zy0AXrmy1K7DKUgKZp1b4g0SrIqI6LPj/Mj8UJLVMWlIGU=; Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1lOFEX-0001mv-TG; Mon, 22 Mar 2021 07:44:17 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOFEU-0001mN-Jd for openvpn-devel@lists.sourceforge.net; Mon, 22 Mar 2021 07:44:14 +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=dccns4SAF8vInudrq/1jVPWumBFRVdSGQIq5YOXavfU=; b=mmJ58lAqQFFXTXVE3/Ts9dJKNx 3El5X9yqJdFG5MLkz2exDxP60pSt+Hk9Hh4nBSFFH014Xx/auhspveU20D+T23PIFVbG3pkp/3qRy 5qsBZ72C5m+PUJs63+pml3xg7KXbayfrGdfEPffJf9oFO9sF7qk3rjO0Wtf25EZ2b0gc=; 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=dccns4SAF8vInudrq/1jVPWumBFRVdSGQIq5YOXavfU=; b=Fk6Ds2rrmHHH77pmTLT4bBj/zW GL0N3KREkYj7NL92RmoQFvhVaz9tsgd1EQ3+21jCXubyTmEj/HDb5Qb6NIzHNvnd8eJaq0GDwrzt5 Bx4/ASvuC+AGXEKysMv4T2mKqLSYiPYZe4a0Ba+XQQ0MZjLToa43QfXeNAk0FVetHApI=; Received: from krn.amebis.si ([93.103.235.207]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) id 1lOFEP-0001Yz-L1 for openvpn-devel@lists.sourceforge.net; Mon, 22 Mar 2021 07:44:14 +0000 Received: by krn.amebis.si (Postfix, from userid 982) id 4E77B18E878A; Mon, 22 Mar 2021 08:44:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rozman.si; s=default; t=1616399043; bh=dccns4SAF8vInudrq/1jVPWumBFRVdSGQIq5YOXavfU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sIPIjXubz6smYeEr/doW7qB66tIYaRyiR1eghosxDhj4wyW1OmVhjp64zudTHorF0 Fh+U2hdE+xkSKXO3R+gmoOJLBR2GC3R6HKioDd+c3mO7UGGUnWIUsfugeU4BVLQ9iw qp0YY3jl24TmsYCkmV6mbnE06R1ImG+Fy4/gT1Do= X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on krn.amebis.doma X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Received: from SR6.amebis.doma (unknown [IPv6:2a01:260:4101:1464:a506:9854:23ad:d966]) by krn.amebis.si (Postfix) with ESMTP id 2FED418E8787; Mon, 22 Mar 2021 08:44:00 +0100 (CET) To: openvpn-devel@lists.sourceforge.net Date: Mon, 22 Mar 2021 08:43:59 +0100 Message-Id: <20210322074359.527-1-simon@rozman.si> X-Mailer: git-send-email 2.30.0.windows.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-Headers-End: 1lOFEP-0001Yz-L1 Subject: [Openvpn-devel] [PATCH v2 4/5] tapctl: Resolve MSVC C4996 warnings 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: , X-Patchwork-Original-From: Simon Rozman via Openvpn-devel From: Kristof Provost via Openvpn-devel Reply-To: Simon Rozman Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox wcsncat() was declared unsafe in favour of wcsncat_s(). However, the string concatenation follows the string length check, making wcsncat() safe too. Code analysis is just not smart enough (yet) to detect this. The code was refactored to use wcscat_s() MSVC is considering as "safe". Signed-off-by: Simon Rozman Acked-by: Gert Doering --- src/tapctl/tap.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/tapctl/tap.c b/src/tapctl/tap.c index dd4a10a3..563c07f6 100644 --- a/src/tapctl/tap.c +++ b/src/tapctl/tap.c @@ -2,7 +2,7 @@ * tapctl -- Utility to manipulate TUN/TAP adapters on Windows * https://community.openvpn.net/openvpn/wiki/Tapctl * - * Copyright (C) 2018-2020 Simon Rozman + * Copyright (C) 2018-2021 Simon Rozman * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 @@ -73,14 +73,15 @@ find_function(const WCHAR *libname, const char *funcname, HMODULE *m) return NULL; } - size_t len = _countof(libpath) - wcslen(libpath) - 1; - if (len < wcslen(libname) + 1) + /* +1 for the path seperator '\' */ + const size_t path_length = wcslen(libpath) + 1 + wcslen(libname); + if (path_length >= _countof(libpath)) { SetLastError(ERROR_INSUFFICIENT_BUFFER); return NULL; } - wcsncat(libpath, L"\\", len); - wcsncat(libpath, libname, len-1); + wcscat_s(libpath, _countof(libpath), L"\\"); + wcscat_s(libpath, _countof(libpath), libname); *m = LoadLibraryW(libpath); if (*m == NULL)