Change in openvpn[master]: dns: fix potential NULL pointer dereference
A message that is not in the archive (sent off-list or not yet received): gerrit.1747646372000.I275bf939f43577427e14890e7093d63c5213ae5d@...2715...
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=email
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.
---
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
src/openvpn/dns.c +35 -26
@@ -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 =env_set_create (gc);const char *dvf =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 =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 = updown_runner->fds[0 ];int wfd = updown_runner->fds[1 ];const char *dvf =write_dns_vars_file (up, o, tt, &gc); -size_t dvf_size =strlen (dvf) +1 ; - -while (1 ) +if (!dvf) { -ssize_t len =write (wfd, dvf, dvf_size); -if (len < dvf_size) - { -if (len ==-1 && errno ==EINTR ) - { -continue ; - } -msg (M_ERR |M_ERRNO ,"could not send dns vars filename" ); - } -break ; +msg (M_ERR ,"could not create dns vars file" ); + status =1 ; } - -while (1 ) +else { -ssize_t len =read (rfd, &status,sizeof (status)); -if (len <sizeof (status)) +size_t dvf_size =strlen (dvf) +1 ; + +while (1 ) { -if (len ==-1 && errno ==EINTR ) +ssize_t len =write (wfd, dvf, dvf_size); +if (len < dvf_size) { -continue ; +if (len ==-1 && errno ==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 =read (rfd, &status,sizeof (status)); +if (len <sizeof (status)) + { +if (len ==-1 && errno ==EINTR ) + { +continue ; + } +msg (M_ERR |M_ERRNO ,"could not receive dns updown status" ); + } +break ; + } }gc_free (&gc);
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1026?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I275bf939f43577427e14890e7093d63c5213ae5d
Gerrit-Change-Number: 1026
Gerrit-PatchSet: 1
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange
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=email
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.
---
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
src/openvpn/dns.c +35 -26
@@ -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 =env_set_create (gc);const char *dvf =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 =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 = updown_runner->fds[0 ];int wfd = updown_runner->fds[1 ];const char *dvf =write_dns_vars_file (up, o, tt, &gc); -size_t dvf_size =strlen (dvf) +1 ; - -while (1 ) +if (!dvf) { -ssize_t len =write (wfd, dvf, dvf_size); -if (len < dvf_size) - { -if (len ==-1 && errno ==EINTR ) - { -continue ; - } -msg (M_ERR |M_ERRNO ,"could not send dns vars filename" ); - } -break ; +msg (M_ERR ,"could not create dns vars file" ); + status =1 ; } - -while (1 ) +else { -ssize_t len =read (rfd, &status,sizeof (status)); -if (len <sizeof (status)) +size_t dvf_size =strlen (dvf) +1 ; + +while (1 ) { -if (len ==-1 && errno ==EINTR ) +ssize_t len =write (wfd, dvf, dvf_size); +if (len < dvf_size) { -continue ; +if (len ==-1 && errno ==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 =read (rfd, &status,sizeof (status)); +if (len <sizeof (status)) + { +if (len ==-1 && errno ==EINTR ) + { +continue ; + } +msg (M_ERR |M_ERRNO ,"could not receive dns updown status" ); + } +break ; + } }gc_free (&gc);
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1026?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I275bf939f43577427e14890e7093d63c5213ae5d
Gerrit-Change-Number: 1026
Gerrit-PatchSet: 2
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
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=email
to look at the new patch set (#3).
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.
---
M src/openvpn/dns.c
1 file changed, 15 insertions(+), 17 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/26/1026/3
src/openvpn/dns.c +15 -17
@@ -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 =env_set_create (gc); -const char *dvf =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,struct dns_updown_runner_info *updown_runner) {
@@ -709,7 +697,7 @@return ; } -int status; +int status =-1 ;if (!updown_runner->required) {
@@ -728,11 +716,19 @@ }struct gc_arena gc =gc_new (); -int rfd = updown_runner->fds[0 ]; -int wfd = updown_runner->fds[1 ]; -const char *dvf =write_dns_vars_file (up, o, tt, &gc); -size_t dvf_size =strlen (dvf) +1 ; +const char *dvf =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 =env_set_create (&gc); +updown_env_set (up, &o->dns_options, tt, es); +env_set_write_file (dvf, es); + +int wfd = updown_runner->fds[1 ]; +size_t dvf_size =strlen (dvf) +1 ;while (1 ) {ssize_t len =write (wfd, dvf, dvf_size);
@@ -747,6 +743,7 @@break ; } +int rfd = updown_runner->fds[0 ];while (1 ) {ssize_t len =read (rfd, &status,sizeof (status));
@@ -761,6 +758,7 @@break ; } +out_free:gc_free (&gc); }
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1026?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I275bf939f43577427e14890e7093d63c5213ae5d
Gerrit-Change-Number: 1026
Gerrit-PatchSet: 3
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: d12fk, flichtenheld, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1026?usp=email )
Change subject: dns: fix potential NULL pointer dereference
......................................................................
Patch Set 3: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1026?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I275bf939f43577427e14890e7093d63c5213ae5d
Gerrit-Change-Number: 1026
Gerrit-PatchSet: 3
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: d12fk <[email protected]...>
Gerrit-Comment-Date: Tue, 20 May 2025 07:33:15 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
PATCH v3 1/1 dns: fix potential NULL pointer dereference
In reply to a message not in the archiveFrom: Heiko Hund <[email protected]...>
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.
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1026
This mail reflects revision 3 of this Change.
Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>
src/openvpn/dns.c +15 -17
@@ -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 =env_set_create (gc); -const char *dvf =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,struct dns_updown_runner_info *updown_runner) {
@@ -709,7 +697,7 @@return ; } -int status; +int status =-1 ;if (!updown_runner->required) {
@@ -728,11 +716,19 @@ }struct gc_arena gc =gc_new (); -int rfd = updown_runner->fds[0 ]; -int wfd = updown_runner->fds[1 ]; -const char *dvf =write_dns_vars_file (up, o, tt, &gc); -size_t dvf_size =strlen (dvf) +1 ; +const char *dvf =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 =env_set_create (&gc); +updown_env_set (up, &o->dns_options, tt, es); +env_set_write_file (dvf, es); + +int wfd = updown_runner->fds[1 ]; +size_t dvf_size =strlen (dvf) +1 ;while (1 ) {ssize_t len =write (wfd, dvf, dvf_size);
@@ -747,6 +743,7 @@break ; } +int rfd = updown_runner->fds[0 ];while (1 ) {ssize_t len =read (rfd, &status,sizeof (status));
@@ -761,6 +758,7 @@break ; } +out_free:gc_free (&gc); }
[Openvpn-devel] [PATCH applied] Re: dns: fix potential NULL pointer dereference
Thanks for this.
Found by Coverity - in the case of a problem in platform_create_temp_file(), the old code would have accessed strlen(NULL) and *boom*. Unlikely, but arguably still possible if something changes with --tmpdir while openvpn is running, or so.
Stared at code v2+v3, like v3 better :-) - tested non-error branch on Linux and FreeBSD (its own can of worms), works.
Your patch has been applied to the master branch.
commit d1045d19bf4ea1f717edac7c67f20e9d8eb3a261
Author: Heiko Hund Date: Tue May 20 09:33:48 2025 +0200
dns: fix potential NULL pointer dereference
Signed-off-by: Heiko Hund <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg31720.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
cron2 has uploaded a new patch set (#4) to the change originally created by d12fk. ( http://gerrit.openvpn.net/c/openvpn/+/1026?usp=email )
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.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg31720.html
---
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
src/openvpn/dns.c +15 -17
@@ -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 =env_set_create (gc); -const char *dvf =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,struct dns_updown_runner_info *updown_runner) {
@@ -708,7 +696,7 @@return ; } -int status; +int status =-1 ;if (!updown_runner->required) {
@@ -727,11 +715,19 @@ }struct gc_arena gc =gc_new (); -int rfd = updown_runner->fds[0 ]; -int wfd = updown_runner->fds[1 ]; -const char *dvf =write_dns_vars_file (up, o, tt, &gc); -size_t dvf_size =strlen (dvf) +1 ; +const char *dvf =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 =env_set_create (&gc); +updown_env_set (up, &o->dns_options, tt, es); +env_set_write_file (dvf, es); + +int wfd = updown_runner->fds[1 ]; +size_t dvf_size =strlen (dvf) +1 ;while (1 ) {ssize_t len =write (wfd, dvf, dvf_size);
@@ -746,6 +742,7 @@break ; } +int rfd = updown_runner->fds[0 ];while (1 ) {ssize_t len =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=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I275bf939f43577427e14890e7093d63c5213ae5d
Gerrit-Change-Number: 1026
Gerrit-PatchSet: 4
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1026?usp=email )
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.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg31720.html
---
M src/openvpn/dns.c
1 file changed, 15 insertions(+), 17 deletions(-)
src/openvpn/dns.c +15 -17
@@ -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 =env_set_create (gc); -const char *dvf =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,struct dns_updown_runner_info *updown_runner) {
@@ -708,7 +696,7 @@return ; } -int status; +int status =-1 ;if (!updown_runner->required) {
@@ -727,11 +715,19 @@ }struct gc_arena gc =gc_new (); -int rfd = updown_runner->fds[0 ]; -int wfd = updown_runner->fds[1 ]; -const char *dvf =write_dns_vars_file (up, o, tt, &gc); -size_t dvf_size =strlen (dvf) +1 ; +const char *dvf =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 =env_set_create (&gc); +updown_env_set (up, &o->dns_options, tt, es); +env_set_write_file (dvf, es); + +int wfd = updown_runner->fds[1 ]; +size_t dvf_size =strlen (dvf) +1 ;while (1 ) {ssize_t len =write (wfd, dvf, dvf_size);
@@ -746,6 +742,7 @@break ; } +int rfd = updown_runner->fds[0 ];while (1 ) {ssize_t len =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=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I275bf939f43577427e14890e7093d63c5213ae5d
Gerrit-Change-Number: 1026
Gerrit-PatchSet: 4
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged