From patchwork Mon Oct 13 16:17:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4505 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:7d42:b0:72f:f16c:e055 with SMTP id fr2csp2016632mab; Mon, 13 Oct 2025 09:18:11 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX+A3Usv6vgqWUfMwc1GblniBR3xaZGzJkRmTY/YhAju37dEeckJhfcqxqc3zWdjuJaU2PkC4hRZkM=@openvpn.net X-Google-Smtp-Source: AGHT+IF1b1btqb6cNUx52tq+Wj68P5xvPqS85/uW79YuFhXlnopa5lg+RDj0ztCpt29TB5WExswd X-Received: by 2002:a05:6808:509f:b0:438:2907:2ead with SMTP id 5614622812f47-4417b47f639mr8882511b6e.50.1760372291680; Mon, 13 Oct 2025 09:18:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1760372291; cv=none; d=google.com; s=arc-20240605; b=HK6dSIr3C3318uU8aOE6QzC1qerxSSu2JgR/rX/PT3DuLqeRgrmk2bjEGOv9JTQYvF AbkaUEGLFYrPW/fQaOl2R1j3AbBwNYNUeNDuEl1UCzAmdm4CTKRCr/h4ovSUdwxBJZgs P9o9Cd1PTd0LsdN381U+byab3gCkL0RzyGTKvvGoGknp855lnmWX4a5Aej6oN517ffS6 l9vocXl8r2qNwEgbxV3xQDIdBgoZCGW6R9wz2Bdu1ZI3bGP6UG3P4GSTyBusuoHG3jLB vzMdzR/6lTcspN73LB1T/1yKqMk1UaJgpRNUJWtQgXMbI9ejpD2yVWt/AJjBTTMfxKpC iZ8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=T+riEgy3rZuJkVrlKXk2OObjmR4qP43N9SOEiKbtDxg=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=fXPCvcUW0ISYtqBCJ3ObCD21jSL5rvSmqUABfEidqLjgPxUXcxoxtzMGQHZ0cE1I/Q zCGKT0YWAVOpqhOdqA47ukUwa+FZ8cgEYC1AlvIQJhYvdIX3eDpdU9Fa/nrPZcUxeVT5 VDGHGa3df8X+gN4Es3617g54HtAX/ONQeuHVwl8jdJjxnED8FUDlGKBoeYNpQoGbfued 8RQCkHLB7XeOhkQ+SKF3TZ3L/DSSqcIEKgw2xxq6BVViG8iXWiFWIzMwMKee3tuAA8Kc 6XZYkYNr3iuWfPNZaSfRY7KbJbUyqc4PGES/inIG1MgZ7TRVktiFhe508jvlPq7n4xPX nmDA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=CKAXUn6N; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=fetjEO00; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=S9bhHozn; 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 5614622812f47-441d012c30dsi1040047b6e.386.2025.10.13.09.18.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Oct 2025 09:18:11 -0700 (PDT) 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=CKAXUn6N; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=fetjEO00; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=S9bhHozn; 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-Owner; bh=T+riEgy3rZuJkVrlKXk2OObjmR4qP43N9SOEiKbtDxg=; b=CKAXUn6NUszlRLKCHuhZ/mkrTf wb0yPVSpSmYn4KcstVjt5Dl3u1zZdhxQj8dJTTYLOoNdx0PffbZgKZlOzK+vyQMZoE8nFomhXG8aZ uJFHP2IMFfWfa17v/bLE0ZnYABv0CFGVD1pLybn/WZBR2XRJsSKrDTFJZ38AP1uCg1Gc=; 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.95) (envelope-from ) id 1v8LFQ-0005tq-NH; Mon, 13 Oct 2025 16:18:08 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1v8LFP-0005tk-Rv for openvpn-devel@lists.sourceforge.net; Mon, 13 Oct 2025 16:18: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: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-Subscribe:List-Post:List-Owner:List-Archive; bh=CrT3cB1lsYzwN7H7M+8JeDieAdPDE+mRJKEH8j/6CNM=; b=fetjEO00liIg0LCGjSGLpgS8CF 3kyxgE90bsr4+SHm/2BwguXeExwSac0Nh1nxhXpqGHqKN2PnJUfQ3NmpYzBbUxMGGg91h4vq8mb/F 6BAck8Pbqpo1j08k1fNwW8sp0cdlEIhZ4vKKGKCgB/MMvCm0n7V+uPbr7XZNHJqjqJm4=; 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-Subscribe: List-Post:List-Owner:List-Archive; bh=CrT3cB1lsYzwN7H7M+8JeDieAdPDE+mRJKEH8j/6CNM=; b=S9bhHoznmzY2dHSmEacsLNA4Hq IKCr5LADihauNH3TfWRD9FQ6cYbvZ8zeL0VlvboLiVZBLjNYbEMzSnn3qtb2ugyiDOSOF4dafnm8a xr4NY4tBnO8pS6/inlslLK0oWV1xAujNyZXBCdv4NggGYyojunx9h8NbwH76hfgN2ENM=; Received: from [193.149.48.134] (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.95) id 1v8LFP-0000f7-0G for openvpn-devel@lists.sourceforge.net; Mon, 13 Oct 2025 16:18:07 +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 59DGI0lY001687 for ; Mon, 13 Oct 2025 18:18:00 +0200 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.1/8.18.1/Submit) id 59DGI0BN001683 for openvpn-devel@lists.sourceforge.net; Mon, 13 Oct 2025 18:18:00 +0200 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Mon, 13 Oct 2025 18:17:53 +0200 Message-ID: <20251013161759.1656-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.49.1 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-2.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 Use more appropriate types. Add casts where necessary but ensure that they are safe. Change-Id: I30a50826350ac3176443cf3bf16d3972609723a2 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/open [...] 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: 1v8LFP-0000f7-0G Subject: [Openvpn-devel] [PATCH v4] dhcp: Clean up type handling of write_dhcp_* 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: =?utf-8?q?1845884136286647044?= X-GMAIL-MSGID: =?utf-8?q?1845884136286647044?= From: Frank Lichtenheld Use more appropriate types. Add casts where necessary but ensure that they are safe. Change-Id: I30a50826350ac3176443cf3bf16d3972609723a2 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1268 --- 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/+/1268 This mail reflects revision 4 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering diff --git a/src/openvpn/dhcp.c b/src/openvpn/dhcp.c index 0893ec7..a34bfca 100644 --- a/src/openvpn/dhcp.c +++ b/src/openvpn/dhcp.c @@ -188,18 +188,13 @@ #if defined(_WIN32) || defined(DHCP_UNIT_TEST) -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - /* * Convert DHCP options from the command line / config file * into a raw DHCP-format options string. */ static void -write_dhcp_u8(struct buffer *buf, const int type, const int data, bool *error) +write_dhcp_u8(struct buffer *buf, const uint8_t type, const uint8_t data, bool *error) { if (!buf_safe(buf, 3)) { @@ -213,13 +208,12 @@ } static void -write_dhcp_u32_array(struct buffer *buf, const int type, const uint32_t *data, +write_dhcp_u32_array(struct buffer *buf, const uint8_t type, const uint32_t *data, const unsigned int len, bool *error) { if (len > 0) { - int i; - const int size = len * sizeof(uint32_t); + const size_t size = len * sizeof(uint32_t); if (!buf_safe(buf, 2 + size)) { @@ -230,12 +224,12 @@ if (size < 1 || size > 255) { *error = true; - msg(M_WARN, "write_dhcp_u32_array: size (%d) must be > 0 and <= 255", size); + msg(M_WARN, "write_dhcp_u32_array: size (%zu) must be > 0 and <= 255", size); return; } buf_write_u8(buf, type); - buf_write_u8(buf, size); - for (i = 0; i < len; ++i) + buf_write_u8(buf, (uint8_t)size); + for (unsigned int i = 0; i < len; ++i) { buf_write_u32(buf, data[i]); } @@ -243,9 +237,9 @@ } static void -write_dhcp_str(struct buffer *buf, const int type, const char *str, bool *error) +write_dhcp_str(struct buffer *buf, const uint8_t type, const char *str, bool *error) { - const int len = strlen(str); + const size_t len = strlen(str); if (!buf_safe(buf, 2 + len)) { *error = true; @@ -259,7 +253,7 @@ return; } buf_write_u8(buf, type); - buf_write_u8(buf, len); + buf_write_u8(buf, (uint8_t)len); buf_write(buf, str, len); } @@ -272,15 +266,14 @@ * 0x1D 0x7 openvpn 0x3 net 0x00 0x0A duckduckgo 0x3 com 0x00 */ static void -write_dhcp_search_str(struct buffer *buf, const int type, const char *const *str_array, +write_dhcp_search_str(struct buffer *buf, const uint8_t type, const char *const *str_array, int array_len, bool *error) { char tmp_buf[256]; - int i; - int len = 0; - int label_length_pos; + size_t len = 0; + size_t label_length_pos; - for (i = 0; i < array_len; i++) + for (int i = 0; i < array_len; i++) { const char *ptr = str_array[i]; @@ -301,7 +294,8 @@ { if (*ptr == '.' || *ptr == '\0') { - tmp_buf[label_length_pos] = (len - label_length_pos) - 1; + /* cast is protected by sizeof(tmp_buf) */ + tmp_buf[label_length_pos] = (char)(len - label_length_pos - 1); label_length_pos = len; if (*ptr == '\0') { @@ -328,14 +322,10 @@ } buf_write_u8(buf, type); - buf_write_u8(buf, len); + buf_write_u8(buf, (uint8_t)len); buf_write(buf, tmp_buf, len); } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - bool build_dhcp_options_string(struct buffer *buf, const struct tuntap_options *o) { diff --git a/src/openvpn/options.c b/src/openvpn/options.c index fec17b4..c0d8fe6 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -1322,7 +1322,7 @@ SHOW_BOOL(dhcp_pre_release); SHOW_STR(domain); SHOW_STR(netbios_scope); - SHOW_INT(netbios_node_type); + SHOW_UNSIGNED(netbios_node_type); SHOW_BOOL(disable_nbt); show_dhcp_option_addrs("DNS", o->dns, o->dns_len); @@ -8001,7 +8001,7 @@ msg(msglevel, "--dhcp-option NBT: parameter (%d) must be 1, 2, 4, or 8", t); goto err; } - o->netbios_node_type = t; + o->netbios_node_type = (uint8_t)t; o->dhcp_options |= DHCP_OPTIONS_DHCP_REQUIRED; } else if (streq(p[1], "WINS") && p[2] && !p[3]) diff --git a/src/openvpn/tun.h b/src/openvpn/tun.h index 741798d..e13f99f 100644 --- a/src/openvpn/tun.h +++ b/src/openvpn/tun.h @@ -104,11 +104,10 @@ const char *netbios_scope; /* NBS (47) */ - int netbios_node_type; /* NBT 1,2,4,8 (46) */ + uint8_t netbios_node_type; /* NBT 1,2,4,8 (46) */ -#define N_DHCP_ADDR \ - 4 /* Max # of addresses allowed for \ - * DNS, WINS, etc. */ +/* Max # of addresses allowed for DNS, WINS, etc. */ +#define N_DHCP_ADDR 4 /* DNS (6) */ in_addr_t dns[N_DHCP_ADDR];