From: "cron2 (Code Review)" Date: Mon, 28 Jul 2025 14:14:40 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <708480a93af92c62502989fc673b1ef544234113-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="v4y4gqTjvgY="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: options: Simplify function setenv_foreign_option List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld , plaisthos Cc: openvpn-devel --v4y4gqTjvgY= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#4) to the change originally created by= flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1112?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 Change subject: options: Simplify function setenv_foreign_option ...................................................................... options: Simplify function setenv_foreign_option 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 Message-Id: <20250728125647.26992-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg32= 396.html Signed-off-by: Gert Doering --- M src/openvpn/options.c 1 file changed, 33 insertions(+), 45 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/12/1112/4 diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 0662b49..d44c102 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, stru= ct env_set *es) +setenv_foreign_option(struct options *o, const char *option, const char *v= alue, struct env_set *es) { - if (len > 0) - { - struct gc_arena gc =3D gc_new(); - struct buffer name =3D alloc_buf_gc(OPTION_PARM_SIZE, &gc); - struct buffer value =3D alloc_buf_gc(OPTION_PARM_SIZE, &gc); - int i; - bool first =3D true; - bool good =3D true; + struct gc_arena gc =3D gc_new(); + struct buffer env_name =3D alloc_buf_gc(OPTION_PARM_SIZE, &gc); + struct buffer env_value =3D alloc_buf_gc(OPTION_PARM_SIZE, &gc); + bool good =3D true; - good &=3D buf_printf(&name, "foreign_option_%d", o->foreign_option= _index + 1); - ++o->foreign_option_index; - for (i =3D 0; i < len; ++i) - { - if (argv[i]) - { - if (!first) - { - good &=3D buf_printf(&value, " "); - } - good &=3D buf_printf(&value, "%s", argv[i]); - first =3D false; - } - } - if (good) - { - setenv_str(es, BSTR(&name), BSTR(&value)); - } - else - { - msg(M_WARN, "foreign_option: name/value overflow"); - } - gc_free(&gc); + good &=3D buf_printf(&env_name, "foreign_option_%d", o->foreign_option= _index + 1); + if (value) + { + good &=3D buf_printf(&env_value, "dhcp-option %s %s", option, valu= e); } + else + { + good &=3D 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_forc= ed(dns)) { /* Set foreign option env vars from --dns config */ - const char *p[] =3D { "dhcp-option", NULL, NULL }; - size_t p_len =3D sizeof(p) / sizeof(p[0]); - - p[1] =3D "DOMAIN"; const struct dns_domain *d =3D dns->search_domains; while (d) { - p[2] =3D d->name; - setenv_foreign_option(o, (const char **)p, p_len, es); + setenv_foreign_option(o, "DOMAIN", d->name, es); d =3D d->next; } @@ -3713,17 +3699,19 @@ { for (int i =3D 0; i < s->addr_count; ++i) { + const char *option; + const char *value; if (s->addr[i].family =3D=3D AF_INET) { - p[1] =3D "DNS"; - p[2] =3D print_in_addr_t(s->addr[i].in.a4.s_addr, = IA_NET_ORDER, &gc); + option =3D "DNS"; + value =3D print_in_addr_t(s->addr[i].in.a4.s_addr,= IA_NET_ORDER, &gc); } else { - p[1] =3D "DNS6"; - p[2] =3D print_in6_addr(s->addr[i].in.a6, 0, &gc); + option =3D "DNS6"; + value =3D 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]) { -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1112?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I7efc77f63734501dfa8a8f5bed17b1a1b4e9e201 Gerrit-Change-Number: 1112 Gerrit-PatchSet: 4 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --v4y4gqTjvgY= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 uploaded patch set #4 to the change originally cr= eated by flichtenheld.

View Change

The following approvals got outd= ated and were removed: Code-Review+2 by cron2

options: Simplify function setenv_foreign_option
=
This was relatively complex for the actual usage.
Looked at the code= because of -Wconversion warnings
related to the len argument. So this s= hould also be
gone.

Change-Id: I7efc77f63734501dfa8a8f5bed17b1a1b= 4e9e201
Signed-off-by: Frank Lichtenheld <frank@...2641...>
Ack= ed-by: Gert Doering <gert@...1296...>
Message-Id: <202507281256= 47.26992-1-gert@...1296...>
URL: https://www.mail-archive.com/openvpn= -devel@lists.sourceforge.net/msg32396.html
Signed-off-by: Gert Doering &= lt;gert@...1296...>
---
M src/openvpn/options.c
1 file changed,= 33 insertions(+), 45 deletions(-)

git pull ssh://gerrit.openvpn.=
net:29418/openvpn refs/changes/12/1112/4
diff --git a/src/openvpn/o=
ptions.c b/src/openvpn/options.c
index 0662b49..d44c102 100= 644
--- a/src/openvpn/options.c
+++ b/src/o= penvpn/options.c
@@ -1067,41 +1067,32 @@
<= /span>
#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 =3D gc_new= ();
- struct buf= fer name =3D alloc_buf_gc(OPTION_PARM_SIZE, &gc);
- struct buffer value =3D alloc_buf_g= c(OPTION_PARM_SIZE, &gc);
- int i;
= - bool first =3D true;
- bool good =3D true;
+ struct gc_arena gc =3D gc_new();
+ struct buffer env_name =3D alloc_buf_= gc(OPTION_PARM_SIZE, &gc);
+ struct buffer env_value =3D alloc_buf_gc(OPTION_PARM_SIZE, &= amp;gc);
+ bool go= od =3D true;

- good &=3D buf_printf(&name, "foreign_option_%= d", o->foreign_option_index + 1);
- ++o->foreign_option_index;
- for (i =3D 0; i < len; ++i)<= /span>
- {
- if (argv[i])
- {
- if (!first)
<= span style=3D"color: hsl(0, 100%, 40%);">- {
- good &=3D buf= _printf(&value, " ");
- }
- good &=3D buf_printf(&value, "%s&quo= t;, argv[i]);
- = first =3D false;
- = }
- if (good)=
- {
<= span style=3D"color: hsl(0, 100%, 40%);">- setenv_str(es, BSTR(&= amp;name), BSTR(&value));
- }
- = else
- {
- msg(M_WARN, &= quot;foreign_option: name/value overflow");
- }
- gc_free(&gc);
+ good &=3D buf_printf(&env_name, "fore= ign_option_%d", o->foreign_option_index + 1);
+ if (value)
+ {
+ good &=3D buf_printf(&env_value, "dhcp-= option %s %s", option, value);
}
+ else
+ {
+ good &=3D buf_printf(&env_value, "dhcp-o= ption %s", option);
+ }
+ if (g= ood)
+ {+ setenv_str(es, BSTR(&= amp;env_name), BSTR(&env_value));
+ ++o->foreign_option_index;
+ }
+ else
+ {
+ = msg(M_WARN, "foreign_option: name/value overflow");+ }
+ gc_free(&gc);
}<= /span>
#endif /* ifndef _WIN32 */

@@ -3678,15 +3669,10 @@

else if (o->up_script &a= mp;& !dns_updown_user_set(dns) && !dns_updown_forced(dns))
{
/* Set foreign option env vars = from --dns config */
- = const char *p[] =3D { "dhcp-option", NULL, NULL };<= br>- size_t p_len =3D size= of(p) / sizeof(p[0]);
-=
- p[1] =3D &quo= t;DOMAIN";
const struct dns_domain *d =3D dns= ->search_domains;
while (d)
= {
- p[= 2] =3D d->name;
- = setenv_foreign_option(o, (const char **)p, p_len, es);
<= span style=3D"color: hsl(120, 100%, 40%);">+ setenv_foreign_opti= on(o, "DOMAIN", d->name, es);

d = =3D d->next;
}

@@ -3713,17 +3699,19 @@

{
= for (int i =3D 0; i < s->addr_count; ++i)
{
+ const char *value;
if (s->addr[i].family =3D=3D AF_INET)
= {
- p[1] =3D "DNS";
- p[2] =3D print_i= n_addr_t(s->addr[i].in.a4.s_addr, IA_NET_ORDER, &gc);
+ option =3D= "DNS";
+ = value =3D print_in_addr_t(s->addr[i].in.a4.s_addr,= IA_NET_ORDER, &gc);
}
<= span> else
{

- p[1= ] =3D "DNS6";
- p[2] =3D print_in6_addr(s->addr[i].in.a6, 0, &= amp;gc);
+ = option =3D "DNS6";
+ value =3D print_in6_addr(s-&g= t;addr[i].in.a6, 0, &gc);
}=
- setenv_f= oreign_option(o, (const char **)p, p_len, es);
+ setenv_foreign_option(o, opt= ion, value, es);
}
= break;
}
@@ -8388,7 = +8376,7 @@
goto err;
= }
#else /* if defined(_WIN32) || defined(TARGET_ANDROID) *= /
- setenv_forei= gn_option(options, (const char **)p, 3, es);
+ setenv_foreign_option(options, p[1], p[2],= es);
#endif /* if defined(_WIN32) || defined(TARGET_ANDRO= ID) */
}
#ifdef _WIN32
@@ -8530,7 +8518,7 @@
else if (streq(p[0], "dhc= p-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])
{
=

To view, visit change 1112. To unsubscribe, or for help wri= ting mail filters, visit set= tings.

=
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7efc77f63734501dfa8a8f5bed1= 7b1a1b4e9e201
Gerrit-Change-Number: 1112
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--v4y4gqTjvgY=--