From: "d12fk (Code Review)" Date: Mon, 19 May 2025 09:22:19 +0000 In-Reply-To: References: Reply-To: heiko@...515..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="he6/ZJuV0VA="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: dns: fix potential NULL pointer dereference List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --he6/ZJuV0VA= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello flichtenheld, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1026?usp=3Demail to look at the new patch set (#2). Change subject: dns: fix potential NULL pointer dereference ...................................................................... dns: fix potential NULL pointer dereference Fix issue reported by Coverity (CID 1646952): Dereferencing a pointer that might be NULL dvf when calling env_set_write_file. In addition to the fix, output a log line in case this happens, because it will influence the communication with the updown runner process, i.e. setting up / tearing down DNS things will not work as expected. Change-Id: I275bf939f43577427e14890e7093d63c5213ae5d Signed-off-by: Heiko Hund --- M src/openvpn/dns.c 1 file changed, 35 insertions(+), 26 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/26/1026/2 diff --git a/src/openvpn/dns.c b/src/openvpn/dns.c index 9927961..1299a13 100644 --- a/src/openvpn/dns.c +++ b/src/openvpn/dns.c @@ -691,12 +691,13 @@ static const char * write_dns_vars_file(bool up, const struct options *o, const struct tuntap = *tt, struct gc_arena *gc) { - struct env_set *es =3D env_set_create(gc); const char *dvf =3D platform_create_temp_file(o->tmp_dir, "dvf", gc); - - updown_env_set(up, &o->dns_options, tt, es); - env_set_write_file(dvf, es); - + if (dvf) + { + struct env_set *es =3D env_set_create(gc); + updown_env_set(up, &o->dns_options, tt, es); + env_set_write_file(dvf, es); + } return dvf; } @@ -731,34 +732,42 @@ int rfd =3D updown_runner->fds[0]; int wfd =3D updown_runner->fds[1]; const char *dvf =3D write_dns_vars_file(up, o, tt, &gc); - size_t dvf_size =3D strlen(dvf) + 1; - - while (1) + if (!dvf) { - ssize_t len =3D write(wfd, dvf, dvf_size); - if (len < dvf_size) - { - if (len =3D=3D -1 && errno =3D=3D EINTR) - { - continue; - } - msg(M_ERR | M_ERRNO, "could not send dns vars filename"); - } - break; + msg(M_ERR, "could not create dns vars file"); + status =3D 1; } - - while (1) + else { - ssize_t len =3D read(rfd, &status, sizeof(status)); - if (len < sizeof(status)) + size_t dvf_size =3D strlen(dvf) + 1; + + while (1) { - if (len =3D=3D -1 && errno =3D=3D EINTR) + ssize_t len =3D write(wfd, dvf, dvf_size); + if (len < dvf_size) { - continue; + if (len =3D=3D -1 && errno =3D=3D EINTR) + { + continue; + } + msg(M_ERR | M_ERRNO, "could not send dns vars filename= "); } - msg(M_ERR | M_ERRNO, "could not receive dns updown status"= ); + break; } - break; + + while (1) + { + ssize_t len =3D read(rfd, &status, sizeof(status)); + if (len < sizeof(status)) + { + if (len =3D=3D -1 && errno =3D=3D EINTR) + { + continue; + } + msg(M_ERR | M_ERRNO, "could not receive dns updown sta= tus"); + } + break; + } } gc_free(&gc); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1026?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: I275bf939f43577427e14890e7093d63c5213ae5d Gerrit-Change-Number: 1026 Gerrit-PatchSet: 2 Gerrit-Owner: d12fk Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newpatchset --he6/ZJuV0VA= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

d12fk uploaded patch set #2 to this change.

View Change

dns: fix potential NULL pointer dereference

Fix issue reported by= Coverity (CID 1646952): Dereferencing a pointer
that might be NULL dvf = when calling env_set_write_file.

In addition to the fix, output a lo= g line in case this happens, because
it will influence the communication= with the updown runner process, i.e.
setting up / tearing down DNS thin= gs will not work as expected.

Change-Id: I275bf939f43577427e14890e70= 93d63c5213ae5d
Signed-off-by: Heiko Hund <heiko@...2662...>
---=
M src/openvpn/dns.c
1 file changed, 35 insertions(+), 26 deletions(-= )

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/26=
/1026/2
diff --git a/src/openvpn/dns.c b/src/openvpn/dns.cindex 9927961..1299a13 100644
--- a/src/openvpn/dns= .c
+++ b/src/openvpn/dns.c
@@ -691,12 +691,= 13 @@
static const char *
write_dns_vars_= file(bool up, const struct options *o, const struct tuntap *tt, struct gc_a= rena *gc)
{
- struct env_set *es =3D env_set_create(gc);
= const char *dvf =3D platform_create_temp_file(o->tmp_dir, "dvf"= ;, gc);
-
- updown_env_set(up, &o->d= ns_options, tt, es);
- = env_set_write_file(dvf, es);
-
+ if (d= vf)
+ {
= + struct env_set *es =3D= env_set_create(gc);
= + updown_env_set(up, &o->dns_options, tt, es);
+ env_set_write_file(dvf, es= );
+ }
<= span> return dvf;
}

= @@ -731,34 +732,42 @@
int rfd =3D updown_runner-&g= t;fds[0];
int wfd =3D updown_runner->fds[1];
const char *dvf =3D write_dns_vars_file(up, o, tt, &= amp;gc);
- size_= t dvf_size =3D strlen(dvf) + 1;
-
- whi= le (1)
+ if (!= dvf)
{
- ssize_t len =3D write(wfd, dvf, dvf_size);
= - if (len < dvf_siz= e)
- {
- if (len =3D= =3D -1 && errno =3D=3D EINTR)
- {
- continue;
- }
- msg(M_ERR | M_ERRNO, "could not send d= ns vars filename");
- = break;
+ = msg(M_ERR, "could not create dns vars file");
+ status =3D 1;
<= br> }
-
- while (1)
+ else
{

- = ssize_t len =3D read(rfd, &status, sizeof(status));
- if (len < sizeof(stat= us))

+ siz= e_t dvf_size =3D strlen(dvf) + 1;
+
+ = while (1)
{
- if (len =3D=3D -1 && errn= o =3D=3D EINTR)
+ = ssize_t len =3D write(wfd, dvf, dvf_size);
+ if (len < dvf_size)
{
- continue;
+ if (len =3D=3D -1 && errn= o =3D=3D EINTR)
+ = {
+ = continue;
+ }
+ msg(M_ERR | M_ERRNO, "could not send= dns vars filename");
}
- msg(M_ERR | M_ERRNO= , "could not receive dns updown status");

+ break;
= }
- = break;
++ while (1)<= br>+ {
+ ssize_t len =3D r= ead(rfd, &status, sizeof(status));

+ if (len < sizeof(status))
<= span style=3D"color: hsl(120, 100%, 40%);">+ {
+ if (len =3D= =3D -1 && errno =3D=3D EINTR)
+ {
+ continue;
+ }
+ msg(M_ERR | M_ERRNO= , "could not receive dns updown status");
+ }
+ break;
+ }
= }

gc_free(&gc);
<= span>

To view, visit change 1026. To unsubscribe, or for hel= p writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I275bf939f43577427e14890e709= 3d63c5213ae5d
Gerrit-Change-Number: 1026
Gerrit-PatchSet: 2
Gerrit-Owner: d12fk <heiko@...515...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
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-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newpatchset
--he6/ZJuV0VA=--