From patchwork Mon Nov 30 17:44:46 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 5825 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:91c9:10b0:11b:d6c:f273 with SMTP id tl9-n1csp13387420lad; Mon, 30 Nov 2026 09:45:03 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHwBJDWWqROYEzn/i41Nu6MMX2hDiocKoKQKrsmk3mPrfMsFgXtPfGp9TH1Q1fg989RteMcHEgLkBM=@openvpn.net X-Received: by 2002:a05:6830:2b20:b0:821:a094:b26d with SMTP id 46e09a7af769-863156719f1mr33998379a34.13.1796060702906; Mon, 30 Nov 2026 09:45:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1796060702; cv=none; d=google.com; s=arc-20260327; b=Gp6kjKyCqWFNui3t2tuKQnrCjnc/LDvZ6vgziCNdPfWacQnw1UDSPR88JVNN4HF4tX +XSO9nIufK0tH4dglUfOl4Dlx6Uvj+ZOKWMbLcpZ8HK/J6UDSwt6gQKHjArs/epd1Zd2 2oCdHSYHpzDoWtiVhQGGn27Dbnnl2tbEN7v/4Ip6WHyprjge8AZEnaVvHAxWTPC2YZnL yIBzHweTqtrqWIWVmXlZs05vsj375Gw5PnXepiTRDPx/0UcOMRcvDZepgzLFn7L+HNtO yAs/2gDamiZQwKOjRI/oPSd9W16gUdoGmODpO2XsKzonY9d3AzOiiUaX8NRgL1qIosh/ Ehjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature; bh=MJ4yCyzZNzSsHsVqvrXQCx7NgaIxe3j9x5YSL07Q6qE=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=ImsFwQ2EBBCywkjfp+ZXlFfjR5xOFOoI9VNMp+vqQV2CAXzAFj+w1QQ0uOnoAeBvk6 PQs8PqVDp4vap6ou4gQlYEIlshb94KfgS1V87CYoXPBsjxb1xMdScJS+Bj6woaki6bMy 7aAHMZc1AgXNnPZqL5zmwQraCt2f5doUVAH07PIT2ydv5IPY2iV18/yoz3bPqi3VY1Lg j5w4gpFEn53QsYFTnQZ9janN0MQaFlI239rh89e345IWp+dlLkkDWG9T2TGC3WdCTZAP zFpCoHDmPs40t5in+gck00HfF6zXmW0muYPtJmdLgK4kDohN6vG2kjqgNyt9OZ6zxbvz mXig==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=KxUmhPLM; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=Qv84X3nS; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Mixx9mRZ; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 46e09a7af769-863c5057d22si3207810a34.90.2026.11.30.09.45.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Nov 2026 09:45:02 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=KxUmhPLM; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=Qv84X3nS; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Mixx9mRZ; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de 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: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=MJ4yCyzZNzSsHsVqvrXQCx7NgaIxe3j9x5YSL07Q6qE=; b=KxUmhPLMm54/RK Gdsc8ZFWFLFuJfvMVce/GjY/2K6GLhTemr+DWqLrn1cvWHCJPNPL4g1Os7PRAHjTACT/c4JBhBOKO MfrP77+uODVK3urkWvz0wmuxvfGFvbVcH62ERCNVrQzwsU1hUKtgOAanQmIbkVqFq0nXFPEL1wUDx BMI=; Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xY5Qy-000000003Qt-2pPr; Mon, 30 Nov 2026 17:45:00 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xY5Qy-000000003Qn-0xil for openvpn-devel@lists.sourceforge.net; Mon, 30 Nov 2026 17:45:00 +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:To:From:Sender:Reply-To:Cc: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-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=zd4JNmM88DQ8K/muudb4KigkrleqwFr55Juu368kIJ0=; b=Qv84X3nSfWZN+lGTSNSRHrO65+ W/4ND3f+BAKtiYuDkbLhC4/CSC7Xq22qUQrW82BKL80zFmNK2htmb6mL/Qzl3qgkIpwHZGTyrLNba mbpwpuNZ9X4HuHnRaTNqKBDutgAuRKvMzbBHwu4DCQXppxTZLRi145k15TAeJeiftPtk=; 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:To:From:Sender:Reply-To:Cc: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-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=zd4JNmM88DQ8K/muudb4KigkrleqwFr55Juu368kIJ0=; b=Mixx9mRZZYD1OVQHvDvO3IMlND 1KRkxDmPHLGZRXKTDOJhSo9Uuam+JUhq/Ci5w4KUdNZHdLPsOxBQcF/qjF0Y4hwouTzXEbJSbDscv VuZZSvAOIelMxjOwdZY3nYAXFNQTrMbmkWeZT/E1TmAiIWyoIisKQG3K7xN+3rjOr+oc=; Received: from [193.149.48.129] (helo=blue.greenie.muc.de) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xY5Qw-0000000064F-1NzP for openvpn-devel@lists.sourceforge.net; Mon, 30 Nov 2026 17:45:00 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.18.1/8.18.1) with ESMTP id 6AUHipqj031995 for ; Mon, 30 Nov 2026 18:44:51 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.2/8.18.1/Submit) id 6AUHiplN031994 for openvpn-devel@lists.sourceforge.net; Mon, 30 Nov 2026 18:44:51 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Mon, 30 Nov 2026 18:44:46 +0100 Message-ID: <20261130174451.31979-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.55.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-1.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Frank Lichtenheld - Switch to msglvl_t for x_msg() argument to make code more in sync with main openvpn source. Fixes one sign conversion warning. - Remove exessive comments about error handling for Reg* - Remove remai [...] Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1xY5Qw-0000000064F-1NzP Subject: [Openvpn-devel] [PATCH v1] tapctl: Various code cleanups 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: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1883306147736419086 X-GMAIL-MSGID: 1883306147736419086 From: Frank Lichtenheld - Switch to msglvl_t for x_msg() argument to make code more in sync with main openvpn source. Fixes one sign conversion warning. - Remove exessive comments about error handling for Reg* - Remove remaining #ifndef UNICODE handling. UNICODE is always enforced (see basic.h). - Remove unnecessary casts for malloc return value. Change-Id: Ia23cdfc2736c2ef1bef044b6c1ad31e56609ca8f Signed-off-by: Frank Lichtenheld Acked-by: Razvan Cojocaru Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2380 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2380 This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above): Razvan Cojocaru diff --git a/src/tapctl/error.h b/src/tapctl/error.h index 4424f56..f1848b6 100644 --- a/src/tapctl/error.h +++ b/src/tapctl/error.h @@ -25,11 +25,13 @@ #include #include +typedef unsigned int msglvl_t; + /* * These globals should not be accessed directly, * but rather through macros or inline functions defined below. */ -extern unsigned int x_debug_level; +extern msglvl_t x_debug_level; extern int x_msg_line_num; /* msg() flags */ @@ -58,7 +60,7 @@ /** Check muting filter */ -bool dont_mute(unsigned int flags); +bool dont_mute(msglvl_t flags); /* Macro to ensure (and teach static analysis tools) we exit on fatal errors */ #ifdef _MSC_VER @@ -84,9 +86,9 @@ EXIT_FATAL(flags); \ } while (false) -void x_msg(const unsigned int flags, const char *format, ...); /* should be called via msg above */ +void x_msg(const msglvl_t flags, const char *format, ...); /* should be called via msg above */ -void x_msg_va(const unsigned int flags, const char *format, va_list arglist); +void x_msg_va(const msglvl_t flags, const char *format, va_list arglist); /* Inline functions */ @@ -98,7 +100,7 @@ /** Return true if flags represent */ static inline bool -msg_test(unsigned int flags) +msg_test(msglvl_t flags) { return check_debug_level(flags); } diff --git a/src/tapctl/tap.c b/src/tapctl/tap.c index a3d83e9..76ec569 100644 --- a/src/tapctl/tap.c +++ b/src/tapctl/tap.c @@ -394,8 +394,9 @@ DWORD dwResult = RegQueryValueEx(hKey, szName, NULL, &dwValueType, NULL, &dwSize); if (dwResult != ERROR_SUCCESS) { - SetLastError(dwResult); /* MSDN does not mention RegQueryValueEx() to set GetLastError(). - But we do have an error code. Set last error manually. */ + /* MSDN does not mention RegQueryValueEx() to set GetLastError(). But + we do have an error code. Set last error manually. */ + SetLastError(dwResult); msg(M_NONFATAL | M_ERRNO, "%s: enumerating \"%ls\" registry value failed", __FUNCTION__, szName); return dwResult; @@ -407,7 +408,7 @@ case REG_EXPAND_SZ: { /* Read value. */ - LPWSTR szValue = (LPWSTR)malloc(dwSize); + LPWSTR szValue = malloc(dwSize); if (szValue == NULL) { msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, dwSize); @@ -417,9 +418,7 @@ dwResult = RegQueryValueEx(hKey, szName, NULL, NULL, (LPBYTE)szValue, &dwSize); if (dwResult != ERROR_SUCCESS) { - SetLastError( - dwResult); /* MSDN does not mention RegQueryValueEx() to set GetLastError(). But - we do have an error code. Set last error manually. */ + SetLastError(dwResult); msg(M_NONFATAL | M_ERRNO, "%s: reading \"%ls\" registry value failed", __FUNCTION__, szName); free(szValue); @@ -429,15 +428,9 @@ if (dwValueType == REG_EXPAND_SZ) { /* Expand the environment strings. */ - DWORD - dwSizeExp = dwSize * 2, dwCountExp = -#ifdef UNICODE - dwSizeExp / sizeof(WCHAR); -#else - dwSizeExp / sizeof(WCHAR) - - 1; /* Note: ANSI version requires one extra char. */ -#endif - LPWSTR szValueExp = (LPWSTR)malloc(dwSizeExp); + DWORD dwSizeExp = dwSize * 2; + DWORD dwCountExp = dwSizeExp / sizeof(WCHAR); + LPWSTR szValueExp = malloc(dwSizeExp); if (szValueExp == NULL) { free(szValue); @@ -465,14 +458,9 @@ { /* Retry with a bigger buffer. */ free(szValueExp); -#ifdef UNICODE dwSizeExp = dwCountExpResult * sizeof(WCHAR); -#else - /* Note: ANSI version requires one extra char. */ - dwSizeExp = (dwCountExpResult + 1) * sizeof(WCHAR); -#endif dwCountExp = dwCountExpResult; - szValueExp = (LPWSTR)malloc(dwSizeExp); + szValueExp = malloc(dwSizeExp); if (szValueExp == NULL) { free(szValue); @@ -555,9 +543,7 @@ continue; } - SetLastError( - dwResult); /* MSDN does not mention RegQueryValueEx() to set GetLastError(). But we - do have an error code. Set last error manually. */ + SetLastError(dwResult); msg(M_NONFATAL | M_ERRNO, "%s: querying \"NetCfgInstanceId\" registry value failed", __FUNCTION__); break; @@ -973,7 +959,7 @@ tap_set_adapter_name(_In_ LPCGUID pguidAdapter, _In_ LPCWSTR szName, _In_ BOOL bSilent) { DWORD dwResult; - int msg_flag = bSilent ? M_WARN : M_NONFATAL; + msglvl_t msg_flag = bSilent ? M_WARN : M_NONFATAL; msg_flag |= M_ERRNO; if (pguidAdapter == NULL || szName == NULL) @@ -999,8 +985,7 @@ dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegKey, 0, KEY_QUERY_VALUE, &hKey); if (dwResult != ERROR_SUCCESS) { - SetLastError(dwResult); /* MSDN does not mention RegOpenKeyEx() to set GetLastError(). But - we do have an error code. Set last error manually. */ + SetLastError(dwResult); msg(msg_flag, "%s: RegOpenKeyEx(HKLM, \"%ls\") failed", __FUNCTION__, szRegKey); goto cleanup_szAdapterId; } @@ -1167,8 +1152,7 @@ dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegKey, 0, KEY_READ, &hKey); if (dwResult != ERROR_SUCCESS) { - SetLastError(dwResult); /* MSDN does not mention RegOpenKeyEx() to set GetLastError(). - But we do have an error code. Set last error manually. */ + SetLastError(dwResult); msg(M_WARN | M_ERRNO, "%s: RegOpenKeyEx(HKLM, \"%ls\") failed", __FUNCTION__, szRegKey); goto cleanup_szAdapterId; } @@ -1187,12 +1171,11 @@ /* Append to the list. */ size_t hwid_size = (wcszlen(szzDeviceHardwareIDs) + 1) * sizeof(WCHAR); size_t name_size = (wcslen(szName) + 1) * sizeof(WCHAR); - struct tap_adapter_node *node = (struct tap_adapter_node *)malloc( - sizeof(struct tap_adapter_node) + hwid_size + name_size); + size_t alloc_size = sizeof(struct tap_adapter_node) + hwid_size + name_size; + struct tap_adapter_node *node = malloc(alloc_size); if (node == NULL) { - msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, - sizeof(struct tap_adapter_node) + hwid_size + name_size); + msg(M_FATAL, "%s: malloc(%zu) failed", __FUNCTION__, alloc_size); dwResult = ERROR_OUTOFMEMORY; goto cleanup_szName; }