From: "cron2 (Code Review)" Date: Tue, 20 May 2025 08:26:04 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., heiko@...515..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <1947143f16a8e2e87939a044a5e00223026751f0-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="kSo/4p5QW5A="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: dns: fix potential NULL pointer dereference List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: d12fk , plaisthos , flichtenheld Cc: openvpn-devel --kSo/4p5QW5A= 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= d12fk. ( http://gerrit.openvpn.net/c/openvpn/+/1026?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 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, inline the write_dns_vars_file() helper function. Also output a log line in case this error happens, because when it happens it will hinder 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 Acked-by: Gert Doering Message-Id: <20250520073354.17091-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg31= 720.html Signed-off-by: Gert Doering --- M src/openvpn/dns.c 1 file changed, 15 insertions(+), 17 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/26/1026/4 diff --git a/src/openvpn/dns.c b/src/openvpn/dns.c index 221e9a9..283ce67 100644 --- a/src/openvpn/dns.c +++ b/src/openvpn/dns.c @@ -688,18 +688,6 @@ return true; } -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); - - return dvf; -} - static void run_up_down_command(bool up, struct options *o, const struct tuntap *tt, s= truct dns_updown_runner_info *updown_runner) { @@ -708,7 +696,7 @@ return; } - int status; + int status =3D -1; if (!updown_runner->required) { @@ -727,11 +715,19 @@ } struct gc_arena gc =3D gc_new(); - 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; + const char *dvf =3D platform_create_temp_file(o->tmp_dir, "dvf", &= gc); + if (!dvf) + { + msg(M_ERR, "could not create dns vars file"); + goto out_free; + } + struct env_set *es =3D env_set_create(&gc); + updown_env_set(up, &o->dns_options, tt, es); + env_set_write_file(dvf, es); + + int wfd =3D updown_runner->fds[1]; + size_t dvf_size =3D strlen(dvf) + 1; while (1) { ssize_t len =3D write(wfd, dvf, dvf_size); @@ -746,6 +742,7 @@ break; } + int rfd =3D updown_runner->fds[0]; while (1) { ssize_t len =3D read(rfd, &status, sizeof(status)); @@ -760,6 +757,7 @@ break; } +out_free: 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: 4 Gerrit-Owner: d12fk Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --kSo/4p5QW5A= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

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

View Change

The following approvals got outdated an= d were removed: Code-Review+2 by cron2

dns: fix potential NULL pointer dereference

F= ix issue reported by Coverity (CID 1646952): Dereferencing a pointer
tha= t might be NULL dvf when calling env_set_write_file.

In addition to = the fix, inline the write_dns_vars_file() helper function.
Also output a= log line in case this error happens, because when it
happens it will hi= nder communication with the updown runner process, i.e.
setting up / tea= ring down DNS things will not work as expected.

Change-Id: I275bf939= f43577427e14890e7093d63c5213ae5d
Signed-off-by: Heiko Hund <heiko@...493...= 2662...>
Acked-by: Gert Doering <gert@...1296...>
Message-Id= : <20250520073354.17091-1-gert@...1296...>
URL: https://www.mail-a= rchive.com/openvpn-devel@lists.sourceforge.net/msg31720.html
Signed-off-= by: Gert Doering <gert@...1296...>
---
M src/openvpn/dns.c
1= file changed, 15 insertions(+), 17 deletions(-)

git pull ssh://g=
errit.openvpn.net:29418/openvpn refs/changes/26/1026/4
diff --git a=
/src/openvpn/dns.c b/src/openvpn/dns.c
index 221e9a9..283ce= 67 100644
--- a/src/openvpn/dns.c
+++ b/src= /openvpn/dns.c
@@ -688,18 +688,6 @@
re= turn true;
}

-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_tem= p_file(o->tmp_dir, "dvf", gc);
-
= - updown_env_set(up, &o->dns_options, tt, es);
- env_set_write_file(dvf, es);<= br>-
- return dvf;
-}
-<= /span>
static void
run_up_down_command(bool up, = struct options *o, const struct tuntap *tt, struct dns_updown_runner_info *= updown_runner)
{
@@ -708,7 +696,7 @@
return;
}
=
- int status;
+ int status =3D -1;

if (!updown_runner->required)
{

@@ -727,11 +715,19 @@
}=

struct gc_arena gc =3D gc_new()= ;
- 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;
+ const char *dvf =3D platform_create_temp_f= ile(o->tmp_dir, "dvf", &gc);
+ if (!dvf)
+ {
+ msg(M_ERR, "could not create dns vars file&q= uot;);
+ g= oto out_free;
+ = }

+ struct env_set *es =3D env_set_create(&gc);
+ updown_env_set(up, &o->= ;dns_options, tt, es);
+
= + int wfd =3D updown_runner->fds[1];
+ size_t dvf_size =3D strlen(dvf) + 1;
while (1)
{
= ssize_t len =3D write(wfd, dvf, dvf_size);
@@ = -746,6 +742,7 @@
break;
= }

+out_fre= e:
gc_free(&gc);
}=


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

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I275bf939f43577427e14890e709= 3d63c5213ae5d
Gerrit-Change-Number: 1026
Gerrit-PatchSet: 4
Gerrit-Owner: d12fk <heiko@...515...>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--kSo/4p5QW5A=--