From: "flichtenheld (Code Review)" Date: Tue, 23 Sep 2025 14:25:32 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="sZKxG62k/Oo="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: dns: Fix bug in error handling when talking to script List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --sZKxG62k/Oo= 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/+/1208?usp=3Demail to review the following change. Change subject: dns: Fix bug in error handling when talking to script ...................................................................... dns: Fix bug in error handling when talking to script Comparing the result of read/write to a size_t value is dangerous C. Since ssize_t and size_t have the same size ssize_t is promoted to size_t, so -1 becomes size_t max value and is not smaller than the expected length. Make sure to compare ssize_t to ssize_t to avoid any suprises. Change-Id: Ic395b6d1dce510bb4b499c5beba61f033a2a860b Signed-off-by: Frank Lichtenheld --- M src/openvpn/dns.c 1 file changed, 5 insertions(+), 6 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/1208/1 diff --git a/src/openvpn/dns.c b/src/openvpn/dns.c index efb888a..2a9e60b 100644 --- a/src/openvpn/dns.c +++ b/src/openvpn/dns.c @@ -642,11 +642,10 @@ while (1) { - ssize_t rlen, wlen; char path[PATH_MAX]; /* Block here until parent sends a path */ - rlen =3D read(dns_pipe_fd[0], &path, sizeof(path)); + ssize_t rlen =3D read(dns_pipe_fd[0], &path, sizeof(path)); if (rlen < 1) { if (rlen =3D=3D -1 && errno =3D=3D EINTR) @@ -665,8 +664,8 @@ /* Unblock parent process */ while (1) { - wlen =3D write(ack_pipe_fd[1], &res, sizeof(res)); - if ((wlen =3D=3D -1 && errno !=3D EINTR) || wlen < sizeof(= res)) + ssize_t wlen =3D write(ack_pipe_fd[1], &res, sizeof(res)); + if ((wlen =3D=3D -1 && errno !=3D EINTR) || wlen < (ssize_= t)sizeof(res)) { /* Not much we can do about errors but exit */ close(dns_pipe_fd[0]); @@ -727,7 +726,7 @@ env_set_write_file(dvf, es); int wfd =3D updown_runner->fds[1]; - size_t dvf_size =3D strlen(dvf) + 1; + ssize_t dvf_size =3D strlen(dvf) + 1; while (1) { ssize_t len =3D write(wfd, dvf, dvf_size); @@ -746,7 +745,7 @@ while (1) { ssize_t len =3D read(rfd, &status, sizeof(status)); - if (len < sizeof(status)) + if (len < (ssize_t)sizeof(status)) { if (len =3D=3D -1 && errno =3D=3D EINTR) { -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1208?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: Ic395b6d1dce510bb4b499c5beba61f033a2a860b Gerrit-Change-Number: 1208 Gerrit-PatchSet: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-MessageType: newchange --sZKxG62k/Oo= 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

dns: Fix bug in error handling when talking to script
Comparing the result of read/write to a size_t value
is dangerous C. Si= nce ssize_t and size_t have the same
size ssize_t is promoted to size_t,= so -1 becomes
size_t max value and is not smaller than the expected
= length.

Make sure to compare ssize_t to ssize_t to avoid any
supr= ises.

Change-Id: Ic395b6d1dce510bb4b499c5beba61f033a2a860b
Signed= -off-by: Frank Lichtenheld <frank@...2641...>
---
M src/openvpn= /dns.c
1 file changed, 5 insertions(+), 6 deletions(-)

git pul= l ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/1208/1
dif=
f --git a/src/openvpn/dns.c b/src/openvpn/dns.c
index efb88= 8a..2a9e60b 100644
--- a/src/openvpn/dns.c
= +++ b/src/openvpn/dns.c
@@ -642,11 +642,10 @@

while (1)
{- ssize_t rlen, wlen= ;
char path[PATH_MAX];

/* Block here until parent sends a path */- rlen =3D read(dns_= pipe_fd[0], &path, sizeof(path));
+ ssize_t rlen =3D read(dns_pipe_fd[0], &pa= th, sizeof(path));
if (rlen < 1)
= {
if (rlen =3D=3D -1 &a= mp;& errno =3D=3D EINTR)
@@ -665,8 +664,8 @@
= /* Unblock parent process */
= while (1)
{
- wlen =3D write(ack_pipe_fd[1], &re= s, sizeof(res));
- = if ((wlen =3D=3D -1 && errno !=3D EINTR) || wlen < si= zeof(res))
+ = ssize_t wlen =3D write(ack_pipe_fd[1], &res, sizeof(res));
+ if ((wlen= =3D=3D -1 && errno !=3D EINTR) || wlen < (ssize_t)sizeof(res))<= /span>
{
/* = Not much we can do about errors but exit */
= close(dns_pipe_fd[0]);
@@ -727,7 +726,7 @@
= env_set_write_file(dvf, es);

int wfd =3D updown_runner->fds[1];

- size_t dvf_size =3D strlen(dvf) + 1;
+ ssize_t dvf_si= ze =3D strlen(dvf) + 1;
while (1)
= {
ssize_t len =3D write(wfd, dvf, dvf= _size);
@@ -746,7 +745,7 @@
while = (1)
{
ssize_t len =3D= read(rfd, &status, sizeof(status));
- if (len < sizeof(status))
+ if (len < (ssize_t)s= izeof(status))

{
= if (len =3D=3D -1 && errno =3D=3D EINTR)
= {

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

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic395b6d1dce510bb4b499c5beba= 61f033a2a860b
Gerrit-Change-Number: 1208
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
--sZKxG62k/Oo=--