From: "d12fk (Code Review)" Date: Mon, 19 May 2025 09:19:36 +0000 References: Reply-To: heiko@...515..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <5617f7beb62fcb16d011a8ecf064a8f67b18cfba-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="J9bBFzOnnWc="; 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 --J9bBFzOnnWc= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1026?usp=3Demail to review the following change. 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 to 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/1 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: 1 Gerrit-Owner: d12fk Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --J9bBFzOnnWc= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

d12fk would like plaisthos and flichtenheld to review t= his change.

V= iew 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 log line in case this happens, because
it will influence to co= mmunication with the updown runner process, i.e.
setting up / tearing do= wn DNS things will not work as expected.

Change-Id: I275bf939f435774= 27e14890e7093d63c5213ae5d
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/1
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
@@ -6= 91,12 +691,13 @@
static const char *
writ= e_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, &qu= ot;dvf", gc);
-
- updown_env_set(up, &= amp;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_f= ile(dvf, es);
+ }<= /span>
return dvf;
}

@@ -731,34 +732,42 @@
int rfd =3D updow= n_runner->fds[0];
int wfd =3D updown_runner->= ;fds[1];
const char *dvf =3D write_dns_vars_file(u= p, 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 &= lt; dvf_size)
- = {
- = if (len =3D=3D -1 && errno =3D=3D EINTR)
- {
- continue;
- }
- msg(M_ERR | M_ERRNO, "coul= d not send dns vars filename");
- }
- break;
+ msg(M_ERR, "could not create dns vars file");
+ status = =3D 1;
}
-
- w= hile (1)
+ els= e
{
- ssize_t len =3D read(rfd, &status, sizeof(status));<= /span>
- if (len &l= t; sizeof(status))
+ = size_t dvf_size =3D strlen(dvf) + 1;
+
+ while (1)
{
- if (len =3D=3D -1 &= amp;& errno =3D=3D EINTR)

+ ssize_t len =3D write(wfd, dvf, dvf_size);=
+ if (len &l= t; dvf_size)
{
- continue;
+ if (len =3D=3D -1 &= amp;& 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;=
}
+
+ while= (1)
+ {
+ ssize= _t len =3D read(rfd, &status, sizeof(status));
+ if (len < sizeof(status))=
+ {
+ i= f (len =3D=3D -1 && errno =3D=3D EINTR)
+ {
+ continue;
<= span style=3D"color: hsl(120, 100%, 40%);">+ }
+ msg(M_ERR= | M_ERRNO, "could not receive dns updown status");
+ }

+ break;

+ }

= }

gc_free(&gc);

To view, visit change 1026. To unsubscribe, or f= or help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I275bf939f43577427e14890e709= 3d63c5213ae5d
Gerrit-Change-Number: 1026
Gerrit-PatchSet: 1
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: newchange
--J9bBFzOnnWc=--