From patchwork Sun Dec 3 09:30:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Rozman X-Patchwork-Id: 126 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director1.mail.ord1d.rsapps.net ([172.27.255.51]) by backend31.mail.ord1d.rsapps.net (Dovecot) with LMTP id E3FvIzpfJFrMfgAAgoeIoA for ; Sun, 03 Dec 2017 15:31:54 -0500 Received: from proxy15.mail.iad3a.rsapps.net ([172.27.255.51]) by director1.mail.ord1d.rsapps.net (Dovecot) with LMTP id eVtNFDpfJFpwWgAANGzteQ ; Sun, 03 Dec 2017 15:31:54 -0500 Received: from smtp39.gate.iad3a ([172.27.255.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy15.mail.iad3a.rsapps.net (Dovecot) with LMTP id clnWGTpfJFrHXAAAHi9b9g ; Sun, 03 Dec 2017 15:31:54 -0500 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.34.181.88] Authentication-Results: smtp39.gate.iad3a.rsapps.net; iprev=pass policy.iprev="216.34.181.88"; 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; dkim=fail (signature verification failed) header.d=rozman.si; dmarc=fail (p=none; dis=none) header.from=rozman.si X-Classification-ID: ff15e67a-d868-11e7-bfa6-782bcb681712-1-1 Received: from [216.34.181.88] ([216.34.181.88:13650] helo=lists.sourceforge.net) by smtp39.gate.iad3a.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 24/06-32323-83F542A5; Sun, 03 Dec 2017 15:31:53 -0500 Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.89) (envelope-from ) id 1eLau2-0007GS-Ev; Sun, 03 Dec 2017 20:30:18 +0000 Received: from sfi-mx-4.v28.ch3.sourceforge.com ([172.29.28.194] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eLau1-0007GM-3h for openvpn-devel@lists.sourceforge.net; Sun, 03 Dec 2017 20:30:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: 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=Q69UwBv54qZLk8eTKtK0tDoE3B9IGmb47sIHHI+juM0=; b=JTEVoYOmBxfo23/HeGMTB4AM1c buz7Y30TZ9b0Wl7QdtDTH72Icnn7hEncRRcrCgpShTdOd3H2EH4g1nODZ7129dftqzwYsCpu3EkeJ a/matcgdGdb7dvO8AcdB7MyTAWPj3NoV36Tj4YkObP06Kb4PTMbwH30Q2iyYtgnRl1lA=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To :MIME-Version:Content-Type:Content-Transfer-Encoding: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=Q69UwBv54qZLk8eTKtK0tDoE3B9IGmb47sIHHI+juM0=; b=XZH/bbNC9474zv0WM0DSYORX1A mWAamA7foIGuQqG/gYFXieyhjBUDCvLKXzzUIl38sowGRDq36KidysuRyqxVPk3a8aJC0UtFXvAcd cN/8ay30i5d3WGED9AfJ8HUiLZ43qinWCgOZZv2PTUDndJ5LbGBBYVIOmOxXBSdANVww=; Received: from amebis01.amebis.si ([89.212.80.145]) by sfi-mx-4.v28.ch3.sourceforge.com with esmtps (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.89) id 1eLatz-0003tV-UQ for openvpn-devel@lists.sourceforge.net; Sun, 03 Dec 2017 20:30:17 +0000 Received: from SR5.amebis.doma (unknown [192.168.100.224]) by amebis01.amebis.si (Postfix) with ESMTP id 737C44071B; Sun, 3 Dec 2017 21:30:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=rozman.si; s=default; t=1512333009; bh=8Gu6fuuDQH2Y/MqfRKFOtPkzr+Hvd4UFRobwYLLxvXo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=rZG8zurF3N5pIkxhei34d1oSHzVwoJgVPHX5jIcegZ8dyTVx2fyIWE5QLG3AgFuUx 9Hq2M3v1VNuzDrB/ZXbYqtdXByR8f3xr9YjPWVRHeaL8FVWM2i2lkiMqDo6vbEQwh2 isOA2j8+nXvWcfpb+7dAmYtsXzFSn6phmLJHw7ds= From: Simon Rozman To: openvpn-devel@lists.sourceforge.net Date: Sun, 3 Dec 2017 21:30:07 +0100 Message-Id: <20171203203007.6628-1-simon@rozman.si> X-Mailer: git-send-email 2.9.0.windows.1 In-Reply-To: <20171203202051.7848-1-simon@rozman.si> References: <20171203202051.7848-1-simon@rozman.si> 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 http://www.dnswl.org/, no trust [89.212.80.145 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1eLatz-0003tV-UQ Subject: [Openvpn-devel] [PATCH v5] openvpnserv: Review MSVC down-casting 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: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox Data size arithmetic was reviewed according to 64-bit MSVC complaints. The warnings were addressed by migrating to size_t, rewriting the code, or silencing the warnings by an explicit cast where appropriate. Acked-by: Selva Nair --- src/openvpnserv/automatic.c | 17 ++++++----------- src/openvpnserv/interactive.c | 12 ++++++------ 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/openvpnserv/automatic.c b/src/openvpnserv/automatic.c index 75c3be2..6f82b4e 100644 --- a/src/openvpnserv/automatic.c +++ b/src/openvpnserv/automatic.c @@ -115,25 +115,20 @@ close_if_open(HANDLE h) static bool match(const WIN32_FIND_DATA *find, LPCTSTR ext) { - int i; - if (find->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { return false; } - if (!_tcslen(ext)) + if (*ext == TEXT('\0')) { return true; } - i = _tcslen(find->cFileName) - _tcslen(ext) - 1; - if (i < 1) - { - return false; - } + /* find the pointer to that last '.' in filename and match ext against the rest */ - return find->cFileName[i] == '.' && !_tcsicmp(find->cFileName + i + 1, ext); + const TCHAR *p = _tcsrchr(find->cFileName, TEXT('.')); + return p && p != find->cFileName && _tcsicmp(p + 1, ext) == 0; } /* @@ -142,14 +137,14 @@ match(const WIN32_FIND_DATA *find, LPCTSTR ext) static bool modext(LPTSTR dest, int size, LPCTSTR src, LPCTSTR newext) { - int i; + size_t i; if (size > 0 && (_tcslen(src) + 1) <= size) { _tcscpy(dest, src); dest [size - 1] = TEXT('\0'); i = _tcslen(dest); - while (--i >= 0) + while (i-- > 0) { if (dest[i] == TEXT('\\')) { diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index ed4603e..5d58ceb 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -280,7 +280,7 @@ ReturnProcessId(HANDLE pipe, DWORD pid, DWORD count, LPHANDLE events) swprintf(buf, _countof(buf), L"0x%08x\n0x%08x\n%s", 0, pid, msg); buf[_countof(buf) - 1] = '\0'; - WritePipeAsync(pipe, buf, wcslen(buf) * 2, count, events); + WritePipeAsync(pipe, buf, (DWORD)(wcslen(buf) * 2), count, events); } static VOID @@ -308,7 +308,7 @@ ReturnError(HANDLE pipe, DWORD error, LPCWSTR func, DWORD count, LPHANDLE events L"0x%1!08x!\n%2!s!\n%3!s!", 0, 0, (LPWSTR) &result, 0, (va_list *) args); - WritePipeAsync(pipe, result, wcslen(result) * 2, count, events); + WritePipeAsync(pipe, result, (DWORD)(wcslen(result) * 2), count, events); #ifdef UNICODE MsgToEventLog(MSG_FLAGS_ERROR, result); #else @@ -452,10 +452,10 @@ out: static BOOL GetStartupData(HANDLE pipe, STARTUP_DATA *sud) { - size_t len; + size_t size, len; BOOL ret = FALSE; WCHAR *data = NULL; - DWORD size, bytes, read; + DWORD bytes, read; bytes = PeekNamedPipeAsync(pipe, 1, &exit_event); if (bytes == 0) @@ -1051,7 +1051,7 @@ netsh_dns_cmd(const wchar_t *action, const wchar_t *proto, const wchar_t *if_nam const wchar_t *fmt = L"netsh interface %s %s dns \"%s\" %s"; /* max cmdline length in wchars -- include room for worst case and some */ - int ncmdline = wcslen(fmt) + wcslen(if_name) + wcslen(addr) + 32 + 1; + size_t ncmdline = wcslen(fmt) + wcslen(if_name) + wcslen(addr) + 32 + 1; wchar_t *cmdline = malloc(ncmdline*sizeof(wchar_t)); if (!cmdline) { @@ -1571,7 +1571,7 @@ RunOpenvpn(LPVOID p) { DWORD written; WideCharToMultiByte(CP_UTF8, 0, sud.std_input, -1, input, input_size, NULL, NULL); - WriteFile(stdin_write, input, strlen(input), &written, NULL); + WriteFile(stdin_write, input, (DWORD)strlen(input), &written, NULL); free(input); }