From: "flichtenheld (Code Review)" Date: Fri, 25 Jul 2025 10:21:55 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <41f1d1a0135ae2cf561803dbad4903acf43402d9-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="9rtBBNtVcNQ="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: options: Clean up function setenv_foreign_option List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --9rtBBNtVcNQ= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: plaisthos. Hello plaisthos, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1112?usp=3Demail to review the following change. Change subject: options: Clean up function setenv_foreign_option ...................................................................... options: Clean up function setenv_foreign_option - Remove unnecessary len > 0 check by reordering the code slightly. - Remove -Wconversion warning by making the len argument size_t. Change-Id: I7efc77f63734501dfa8a8f5bed17b1a1b4e9e201 Signed-off-by: Frank Lichtenheld --- M src/openvpn/options.c 1 file changed, 25 insertions(+), 29 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/12/1112/1 diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 70b5799..4d94211 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -1067,41 +1067,37 @@ #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 *argv[], size_t len, s= truct 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 name =3D alloc_buf_gc(OPTION_PARM_SIZE, &gc); + struct buffer value =3D alloc_buf_gc(OPTION_PARM_SIZE, &gc); + bool first =3D true; + 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) + good &=3D buf_printf(&name, "foreign_option_%d", o->foreign_option_ind= ex + 1); + for (size_t i =3D 0; i < len; ++i) + { + if (argv[i]) { - if (argv[i]) + if (!first) { - if (!first) - { - good &=3D buf_printf(&value, " "); - } - good &=3D buf_printf(&value, "%s", argv[i]); - first =3D false; + 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); } + if (good) + { + setenv_str(es, BSTR(&name), BSTR(&value)); + ++o->foreign_option_index; + } + else + { + msg(M_WARN, "foreign_option: name/value overflow"); + } + gc_free(&gc); } #endif /* ifndef _WIN32 */ @@ -3679,7 +3675,7 @@ { /* 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]); + const size_t p_len =3D sizeof(p) / sizeof(p[0]); p[1] =3D "DOMAIN"; const struct dns_domain *d =3D dns->search_domains; -- 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: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-MessageType: newchange --9rtBBNtVcNQ= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: plaisthos.

flichtenheld would like plaisthos to review this change.

V= iew Change

options: Clean up function setenv_foreign_option

- Re= move unnecessary len > 0 check by reordering
the code slightly.
= - Remove -Wconversion warning by making the len argument
size_t.
Change-Id: I7efc77f63734501dfa8a8f5bed17b1a1b4e9e201
Signed-off-by: Fr= ank Lichtenheld <frank@...2641...>
---
M src/openvpn/options.c<= br>1 file changed, 25 insertions(+), 29 deletions(-)

git pull ssh=
://gerrit.openvpn.net:29418/openvpn refs/changes/12/1112/1
diff --=
git a/src/openvpn/options.c b/src/openvpn/options.c
index 7= 0b5799..4d94211 100644
--- a/src/openvpn/options.c+++ b/src/openvpn/options.c
@@ -1067,41 +1067,37 @@=

#ifndef _WIN32
static = void
-setenv_foreign_op= tion(struct options *o, const char *argv[], int len, struct env_set *es)
+setenv_foreign_option(= struct options *o, const char *argv[], size_t len, struct env_set *es)
{
- if = (len > 0)
- {
- struct gc_arena g= c =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 name =3D all= oc_buf_gc(OPTION_PARM_SIZE, &gc);
+ struct buffer value =3D alloc_buf_gc(OPTION_PARM_SIZE= , &gc);
+ bool= first =3D true;
+ = 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 < le= n; ++i)
+ good &am= p;=3D buf_printf(&name, "foreign_option_%d", o->foreign_op= tion_index + 1);
+ = for (size_t i =3D 0; i < len; ++i)
+ {
+ if (argv[i])
{
- if (argv[i])
+ if (!first)
{

- = if (!first)
= - {
- = good &=3D buf_printf(&value, " ");
- }- good &=3D b= uf_printf(&value, "%s", argv[i]);
- first =3D false;
+ good &=3D buf_pr= intf(&value, " ");
}
<= span style=3D"color: hsl(120, 100%, 40%);">+ good &=3D buf_p= rintf(&value, "%s", 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);
}
<= span style=3D"color: hsl(120, 100%, 40%);">+ if (good)

+ {
+ setenv_str(es, BSTR(&name), BSTR(&v= alue));
+ ++o-= >foreign_option_index;
+ }
+ else=
+ {
+ msg(M_WARN, "foreign= _option: name/value overflow");

+ }
- size_t p_len =3D sizeof(p) / sizeof(p[0]);
+ const size_t p_len =3D sizeo= f(p) / sizeof(p[0]);

p[1] =3D &q= uot;DOMAIN";
const struct dns_domain *d =3D d= ns->search_domains;

To view, visit <= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/1112?usp=3Demail">change 11= 12. 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: 1
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-MessageType: newchange
--9rtBBNtVcNQ=--