From patchwork Mon Jul 28 12:56:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4334 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:c08a:b0:671:5a2c:6455 with SMTP id jr10csp52739mab; Mon, 28 Jul 2025 05:57:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUvE2Rn6ygXXCxUL+UfsGHQGuRr7Z7odGMfoCypi/w9ZTj8Ld8f021oeirM2hQn0o81N10cWdMD6wg=@openvpn.net X-Google-Smtp-Source: AGHT+IH/Iq/n60pUtZ7bNWE5V3c4Ge0VUG8XM/fhIWPvA2YsBnveW2tuIx9CFSaofk8+FX43VFsC X-Received: by 2002:a05:6808:6903:b0:40c:fc48:33b5 with SMTP id 5614622812f47-42bb7bc2960mr6432326b6e.12.1753707425798; Mon, 28 Jul 2025 05:57:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1753707425; cv=none; d=google.com; s=arc-20240605; b=dQ8GzUVb8MO/wMXNzXXv+AjvxmsdjhrfF0e2qbOHjBawSxN2gLdBIvlSRSdfOzrBg9 vtD1a8dJZ8QuBn285X5ZdoqVAhx6dfaTofEKy6kwoJS/KyymFEIvTfAAmNa23aqCLq4i fjiAd7RAx2UQkzFX7vlRl7pQOpjOWIaS5JDVnrDjYGuv5MnVhNEtjb5sBg1/TSIgckcI 7XI3KiCuXU0+rlZTfQ+AzPm8QG3NUjI+LnkAaG6QXnkA/ZLXKvsJAUmVGMxhiqHGoips VGX2ZfYS5OdVeIuvQaplxBvTZJd8VL09twn/NQoxmyrOa9rv81EnXVvRcLMrzFJs/kLc /9yg== 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=+HlGhLNFk7PYlk2HXSxcpj0/pClQjJu+L3D45133B+M=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=lCytisyfQAUn8wR6I07hRn1JHdppjOcFVn1tou6pvWuvZWJ5wpN7qjN78ku1o14x7b 2XfgjJ9O6OGOKhnQpMX7maJHkt3m5pEAhG0pydGz9psZgWnFG3IIyRoUgWMRG3eI4+cQ C70XvikH/ByNlVR3exa3TOzRJuBelsxvVfv9vD8tZCquDKukrnXD57l9hLD6azm4tqWk nThN2fGa20LLlhlDhLdnTD5dCBuASVU04uKC1YY5jxoedkAGry0mPvIgQ7cPEwKVi/8C QLewKs3oab6Y7TiaJ/aNvQgZ3sf4Rkf8b/KiCEwQcAeYl54LLqrfJQjxGYauqdRD/BZI qIZg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=f5XI7DhM; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="k/qiwxm8"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=ES3sI36j; 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-42c7cce18d3si1997693b6e.100.2025.07.28.05.57.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jul 2025 05:57:05 -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=f5XI7DhM; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="k/qiwxm8"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=ES3sI36j; 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=+HlGhLNFk7PYlk2HXSxcpj0/pClQjJu+L3D45133B+M=; b=f5XI7DhMi5okOuu98vJPo7jTUk kanCWIfa5djbUjwCwEYfWdwuSfV8KnKKcDNpiKCUCAeNRaXmWIkCEs6jos9UbBaI1nAPgjHkT3bsT ISejxk2ERMkzli4HxjdbmhDy9aqEUwtsVrqbQoMrp0RUK65JuvtNXSTvvmxAmElKdfSI=; 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 1ugNPa-0000MA-Qk; Mon, 28 Jul 2025 12:57:02 +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 1ugNPZ-0000Ll-2k for openvpn-devel@lists.sourceforge.net; Mon, 28 Jul 2025 12:57:01 +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=nHWrO+VaV67aYvTUbBmB8HgRZyDwUPQ2Nq9xLFmxDoo=; b=k/qiwxm86Y2y0iUf7xbIIFhYee E54SSRhk1kTyJzElcnY2hpvEv/S/NY3PU5Ry55C36cmZGnhfRnR+dFKw2eIMjVxWhWLdhK8hLQHTW 3ttq3CV3fYrXNn9cmxa+JTdJprGShF+Z6aHzoOuR6wjClxAerI0oQlZETD4E0FH16n/M=; 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=nHWrO+VaV67aYvTUbBmB8HgRZyDwUPQ2Nq9xLFmxDoo=; b=ES3sI36jeDcMI6HeH2emi7b23m O3MxFOjFAwbHmFznxLARzYlno0QrQ8IDqD/7LENpEAZEBbiunqX/Ks8IrDb3H78/O0A8ZMtBbro2d BctsdXXghxNYzlOLoBIpFi+AyOzWi+Lfdh34gyxRPcT2/LQT4fb3OxFVDbK2Fu9syyNY=; Received: from [193.149.48.143] (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 1ugNPX-0007bt-RG for openvpn-devel@lists.sourceforge.net; Mon, 28 Jul 2025 12:57:00 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.17.1.9/8.17.1.9) with ESMTP id 56SCumqW027017 for ; Mon, 28 Jul 2025 14:56:48 +0200 Received: (from gert@localhost) by blue.greenie.muc.de (8.17.1.9/8.17.1.9/Submit) id 56SCumSY027016 for openvpn-devel@lists.sourceforge.net; Mon, 28 Jul 2025 14:56:48 +0200 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Mon, 28 Jul 2025 14:56:41 +0200 Message-ID: <20250728125647.26992-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.49.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 This was relatively complex for the actual usage. Looked at the code because of -Wconversion warnings related to the len argument. So this should also be gone. 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: 1ugNPX-0007bt-RG Subject: [Openvpn-devel] [PATCH v2] options: Simplify function setenv_foreign_option 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?1838895517504898817?= X-GMAIL-MSGID: =?utf-8?q?1838895517504898817?= From: Frank Lichtenheld This was relatively complex for the actual usage. Looked at the code because of -Wconversion warnings related to the len argument. So this should also be gone. Change-Id: I7efc77f63734501dfa8a8f5bed17b1a1b4e9e201 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering --- 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/+/1112 This mail reflects revision 2 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 70b5799..8757581 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -1067,41 +1067,32 @@ #ifndef _WIN32 static void -setenv_foreign_option(struct options *o, const char *argv[], int len, struct env_set *es) +setenv_foreign_option(struct options *o, const char *option, const char *value, struct env_set *es) { - if (len > 0) - { - struct gc_arena gc = gc_new(); - struct buffer name = alloc_buf_gc(OPTION_PARM_SIZE, &gc); - struct buffer value = alloc_buf_gc(OPTION_PARM_SIZE, &gc); - int i; - bool first = true; - bool good = true; + struct gc_arena gc = gc_new(); + struct buffer env_name = alloc_buf_gc(OPTION_PARM_SIZE, &gc); + struct buffer env_value = alloc_buf_gc(OPTION_PARM_SIZE, &gc); + bool good = true; - good &= buf_printf(&name, "foreign_option_%d", o->foreign_option_index + 1); - ++o->foreign_option_index; - for (i = 0; i < len; ++i) - { - if (argv[i]) - { - if (!first) - { - good &= buf_printf(&value, " "); - } - good &= buf_printf(&value, "%s", argv[i]); - first = false; - } - } - if (good) - { - setenv_str(es, BSTR(&name), BSTR(&value)); - } - else - { - msg(M_WARN, "foreign_option: name/value overflow"); - } - gc_free(&gc); + good &= buf_printf(&env_name, "foreign_option_%d", o->foreign_option_index + 1); + if (value) + { + good &= buf_printf(&env_value, "dhcp-option %s %s", option, value); } + else + { + good &= buf_printf(&env_value, "dhcp-option %s", option); + } + if (good) + { + setenv_str(es, BSTR(&env_name), BSTR(&env_value)); + ++o->foreign_option_index; + } + else + { + msg(M_WARN, "foreign_option: name/value overflow"); + } + gc_free(&gc); } #endif /* ifndef _WIN32 */ @@ -3678,15 +3669,10 @@ else if (o->up_script && !dns_updown_user_set(dns) && !dns_updown_forced(dns)) { /* Set foreign option env vars from --dns config */ - const char *p[] = { "dhcp-option", NULL, NULL }; - size_t p_len = sizeof(p) / sizeof(p[0]); - - p[1] = "DOMAIN"; const struct dns_domain *d = dns->search_domains; while (d) { - p[2] = d->name; - setenv_foreign_option(o, (const char **)p, p_len, es); + setenv_foreign_option(o, "DOMAIN", d->name, es); d = d->next; } @@ -3713,17 +3699,19 @@ { for (int i = 0; i < s->addr_count; ++i) { + const char *option; + const char *value; if (s->addr[i].family == AF_INET) { - p[1] = "DNS"; - p[2] = print_in_addr_t(s->addr[i].in.a4.s_addr, IA_NET_ORDER, &gc); + option = "DNS"; + value = print_in_addr_t(s->addr[i].in.a4.s_addr, IA_NET_ORDER, &gc); } else { - p[1] = "DNS6"; - p[2] = print_in6_addr(s->addr[i].in.a6, 0, &gc); + option = "DNS6"; + value = print_in6_addr(s->addr[i].in.a6, 0, &gc); } - setenv_foreign_option(o, (const char **)p, p_len, es); + setenv_foreign_option(o, option, value, es); } break; } @@ -8388,7 +8376,7 @@ goto err; } #else /* if defined(_WIN32) || defined(TARGET_ANDROID) */ - setenv_foreign_option(options, (const char **)p, 3, es); + setenv_foreign_option(options, p[1], p[2], es); #endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */ } #ifdef _WIN32 @@ -8530,7 +8518,7 @@ else if (streq(p[0], "dhcp-option") && p[1] && !p[3]) { VERIFY_PERMISSION(OPT_P_DHCPDNS); - setenv_foreign_option(options, (const char **)p, 3, es); + setenv_foreign_option(options, p[1], p[2], es); } else if (streq(p[0], "route-method") && p[1] && !p[2]) {