From: "flichtenheld (Code Review)" Date: Mon, 28 Jul 2025 12:28:56 +0000 In-Reply-To: References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, gert@...1296... Message-ID: <28d649784aefbfd0d9e44ca5164bc172f6313832-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="vFa7UJxuCAE="; 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: plaisthos Cc: openvpn-devel --vFa7UJxuCAE= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1112?usp=3Demail to look at the new patch set (#2). 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 --- M src/openvpn/options.c 1 file changed, 33 insertions(+), 45 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/12/1112/2 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, 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: 2 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: cron2 Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newpatchset --vFa7UJxuCAE= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

flichtenheld uploaded patch set #2 to this change.

<= p>View C= hange

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
Si= gned-off-by: Frank Lichtenheld <frank@...2641...>
---
M src/ope= nvpn/options.c
1 file changed, 33 insertions(+), 45 deletions(-)

=
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/12/1112/2
diff --git a/src/openvpn/options.c b/src/openvpn/options.cindex 70b5799..8757581 100644
--- a/src/openvpn/opti= ons.c
+++ b/src/openvpn/options.c
@@ -1067,= 41 +1067,32 @@

#ifndef _WIN32
= static void
-set= env_foreign_option(struct options *o, const char *argv[], int len, struct e= nv_set *es)
+setenv_f= oreign_option(struct options *o, const char *option, const char *value, str= uct env_set *es)
{
- if (len > 0)
- {
- = struct gc_arena gc =3D gc_new();
- struct buffer name =3D alloc_buf_gc(OPTION_PARM_SIZE= , &gc);
- st= ruct 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();
+ struc= t 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(&= amp;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, " ");<= br>- }
<= span style=3D"color: hsl(0, 100%, 40%);">- 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&qu= ot;);
- }=
- gc_free(&gc);

+ good &=3D buf_= printf(&env_name, "foreign_option_%d", o->foreign_option_i= ndex + 1);
+ if (v= alue)
+ {+ good &=3D buf_pr= intf(&env_value, "dhcp-option %s %s", option, value);<= br> }
+ = else
+ {+ good &=3D buf_pri= ntf(&env_value, "dhcp-option %s", option);
+ }
+ if (good)
+ {
+ ++o->foreign_o= ption_index;
+ }
+ else
+ {

+ msg(M_WARN, "foreign_option: name= /value overflow");
+ }
+ gc_fre= e(&gc);
}
#endif /* ifndef _WIN32 */<= /span>

@@ -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[] =3D { "dhcp-op= tion", NULL, NULL };
- size_t p_len =3D sizeof(p) / sizeof(p[0]);
-
- p[1] =3D "DOMAIN";
c= onst 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 &= quot;DNS";
- = p[2] =3D print_in_addr_t(s->addr[i].in.a4.s_addr, IA_N= ET_ORDER, &gc);
+= option =3D "DNS";
+ value =3D print_i= n_addr_t(s->addr[i].in.a4.s_addr, IA_NET_ORDER, &gc);
}
else {
- p[1] =3D "DNS6";
- p[2] =3D prin= t_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_le= n, 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 def= ined(_WIN32) || defined(TARGET_ANDROID) */
} #ifdef _WIN32
@@ -8530,7 +8518,7 @@
else if (streq(p[0], "dhcp-option") && p[1] &&a= mp; !p[3])
{
VERIFY_PERMISSIO= N(OPT_P_DHCPDNS);
- = setenv_foreign_option(options, (const char **)p, 3, es);
+ setenv_foreign_option(opti= ons, p[1], p[2], es);
}
else if (= streq(p[0], "route-method") && p[1] && !p[2])
{

To view, visit change 1112<= /a>. To unsubscribe, or for help writing mail filters, visit settings.

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