From patchwork Sun Nov 12 22:49:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Rozman X-Patchwork-Id: 80 X-Patchwork-Delegate: selva.nair@gmail.com Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director4.mail.ord1d.rsapps.net ([172.28.255.1]) by backend31.mail.ord1d.rsapps.net (Dovecot) with LMTP id TXnPAP1qCVo9UwAAgoeIoA for ; Mon, 13 Nov 2017 04:50:53 -0500 Received: from director9.mail.ord1c.rsapps.net ([172.28.255.1]) by director4.mail.ord1d.rsapps.net (Dovecot) with LMTP id a8AmC/1qCVqDVgAAHDmxtw ; Mon, 13 Nov 2017 04:50:53 -0500 Received: from smtp40.gate.ord1a ([172.28.255.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by director9.mail.ord1c.rsapps.net (Dovecot) with LMTP id pCx1BP1qCVqALwAA4V03VA ; Mon, 13 Nov 2017 04:50:53 -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: smtp40.gate.ord1a.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: 2174b28a-c858-11e7-9ae4-001e4f11f45a-1-1 Received: from [216.34.181.88] ([216.34.181.88:18014] helo=lists.sourceforge.net) by smtp40.gate.ord1a.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 6F/93-11194-AFA690A5; Mon, 13 Nov 2017 04:50:50 -0500 Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.89) (envelope-from ) id 1eEBNX-00068I-Pw; Mon, 13 Nov 2017 09:50:07 +0000 Received: from sfi-mx-3.v28.ch3.sourceforge.com ([172.29.28.193] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eEBNV-000689-PG for openvpn-devel@lists.sourceforge.net; Mon, 13 Nov 2017 09:50:05 +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=B5aB/QaVtbI3mqArSdlBypIrTiYsU9qiiyysvnvh2wY=; b=iiO5dvERpyeVgwEcAMLzmz5cYF 7YFguyPbMER1R3cTBmdGA0w5F5hJAuGwtZ7tEGwxTAWx01tz4kJOK16/ilqlCkg8rKucs3D6mDcuj ymI4aMsF03Gg/Tg6n9B7vPSjDrL8i+mwGcQDVVJOkfG3/iYbj7FWxofY0M/4NJUsSy0Y=; 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=B5aB/QaVtbI3mqArSdlBypIrTiYsU9qiiyysvnvh2wY=; b=TZxV8V+dHD/2M5Ix2fs8F4lzAF jNcBIPbsecqVLc8Bk87TEOy2SV9LUoN5n1UKOtZyPafg8qe45cG9oF9+TC9IlR0NPk1/2vBaKwChU cLFQqrPFboN8Qxz2U5GjPntAlzbfvS/B4GrCRKDr6hYuCyicyxznTqwqi0/HK2Jh6fxM=; Received: from amebis01.amebis.si ([89.212.80.145]) by sfi-mx-3.v28.ch3.sourceforge.com with esmtps (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.89) id 1eEBNR-0005F0-UR for openvpn-devel@lists.sourceforge.net; Mon, 13 Nov 2017 09:50:05 +0000 Received: from SR5.amebis.doma (unknown [192.168.100.225]) by amebis01.amebis.si (Postfix) with ESMTP id 56D5E407C1; Mon, 13 Nov 2017 10:49:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=rozman.si; s=default; t=1510566594; bh=+kEsduMulh9JKJvVV85zuwmR9l0T+B3o/HbgxIe13Yw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=Knuo9FJaRO81SDAamU9OntGDj4KidWXqLsJ6q5zfb0d0ej1Ax8FLx2htesjhlfwAp FOuscw/9LTuG7eP6GnpCHUhhj3FSGkJpnPDl6dPVgJgCD8RKxynAf82sON4WuCy0DT IP/JWLU1iVW7h9ZdGeiT45i/FIj3WUkYPlOg75Wc= From: Simon Rozman To: openvpn-devel@lists.sourceforge.net Date: Mon, 13 Nov 2017 10:49:52 +0100 Message-Id: <20171113094952.33364-1-simon@rozman.si> X-Mailer: git-send-email 2.9.0.windows.1 In-Reply-To: <99D61A626FDA8A4B90A270669121BE108588B957@PLANJAVA.amebis.doma> References: <99D61A626FDA8A4B90A270669121BE108588B957@PLANJAVA.amebis.doma> 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 0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1eEBNR-0005F0-UR Subject: [Openvpn-devel] [PATCH v2] 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. --- src/openvpnserv/automatic.c | 20 ++++---------------- src/openvpnserv/interactive.c | 12 ++++++------ 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/openvpnserv/automatic.c b/src/openvpnserv/automatic.c index 75c3be2..4d5501b 100644 --- a/src/openvpnserv/automatic.c +++ b/src/openvpnserv/automatic.c @@ -115,25 +115,13 @@ 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)) - { - return true; - } - - i = _tcslen(find->cFileName) - _tcslen(ext) - 1; - if (i < 1) - { - return false; - } - - 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 +130,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); }