From: "flichtenheld (Code Review)" Date: Tue, 13 Jan 2026 15:42:23 +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="4r7deCSlhd0="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: port-share: Check return value of fork() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --4r7deCSlhd0= 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/+/1470?usp=3Demail to review the following change. Change subject: port-share: Check return value of fork() ...................................................................... port-share: Check return value of fork() While here, do some small C11 code cleanup. Reported-By: Joshua Rogers Found-By: ZeroPath (https://zeropath.com) Github: openvpn-private-issues#12 Change-Id: I5eac1b31ae40eb957e2c12ca6c37b491fef32847 Signed-off-by: Frank Lichtenheld --- M src/openvpn/ps.c 1 file changed, 18 insertions(+), 16 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/70/1470/1 diff --git a/src/openvpn/ps.c b/src/openvpn/ps.c index ed2d5c9f..c9da426 100644 --- a/src/openvpn/ps.c +++ b/src/openvpn/ps.c @@ -800,12 +800,9 @@ port_share_open(const char *host, const char *port, const int max_initial_= buf, const char *journal_dir) { - pid_t pid; socket_descriptor_t fd[2]; struct openvpn_sockaddr hostaddr; struct port_share *ps; - int status; - struct addrinfo *ai; ALLOC_OBJ_CLEAR(ps, struct port_share); ps->foreground_fd =3D -1; @@ -814,13 +811,15 @@ /* * Get host's IP address */ - - status =3D - openvpn_getaddrinfo(GETADDR_RESOLVE | GETADDR_FATAL, host, port, 0= , NULL, AF_UNSPEC, &ai); - ASSERT(status =3D=3D 0); - ASSERT(sizeof(hostaddr.addr) >=3D ai->ai_addrlen); - memcpy(&hostaddr.addr.sa, ai->ai_addr, ai->ai_addrlen); - freeaddrinfo(ai); + { + struct addrinfo *ai; + int status =3D + openvpn_getaddrinfo(GETADDR_RESOLVE | GETADDR_FATAL, host, por= t, 0, NULL, AF_UNSPEC, &ai); + ASSERT(status =3D=3D 0); + ASSERT(sizeof(hostaddr.addr) >=3D ai->ai_addrlen); + memcpy(&hostaddr.addr.sa, ai->ai_addr, ai->ai_addrlen); + freeaddrinfo(ai); + } if (msg_test(D_PS_PROXY_DEBUG)) { @@ -836,19 +835,22 @@ */ if (socketpair(PF_UNIX, SOCK_DGRAM, 0, fd) =3D=3D -1) { - msg(M_WARN, "PORT SHARE: socketpair call failed"); + msg(M_WARN | M_ERRNO, "PORT SHARE: socketpair call failed"); goto error; } /* * Fork off background proxy process. */ - pid =3D fork(); + pid_t pid =3D fork(); - if (pid) + if (pid < 0) { - int status; - + msg(M_WARN | M_ERRNO, "PORT SHARE: fork failed"); + goto error; + } + else if (pid) + { /* * Foreground Process */ @@ -862,7 +864,7 @@ set_cloexec(fd[0]); /* wait for background child process to initialize */ - status =3D recv_control(fd[0]); + int status =3D recv_control(fd[0]); if (status =3D=3D RESPONSE_INIT_SUCCEEDED) { /* note that this will cause possible EAGAIN when writing to -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1470?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newchange Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I5eac1b31ae40eb957e2c12ca6c37b491fef32847 Gerrit-Change-Number: 1470 Gerrit-PatchSet: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos --4r7deCSlhd0= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: plaisthos.

flichtenheld would like plaisthos to review this change.

V= iew Change

port-share: Check return value of fork()
While here, do some small C11 code cleanup.

Reported-By: Joshua= Rogers <contact@...2949...>
Found-By: ZeroPath (https://zeropath.= com)
Github: openvpn-private-issues#12
Change-Id: I5eac1b31ae40eb957e= 2c12ca6c37b491fef32847
Signed-off-by: Frank Lichtenheld <frank@...2716...= 1...>
---
M src/openvpn/ps.c
1 file changed, 18 insertions(+), = 16 deletions(-)

git pull ssh://gerrit.openvpn.ne=
t:29418/openvpn refs/changes/70/1470/1
diff --git a/src/openvpn/ps.=
c b/src/openvpn/ps.c
index ed2d5c9f..c9da426 100644<= br>--- a/src/openvpn/ps.c
+++ b/src/openvpn/ps.c
@@ -800,12 +800,9 @@
port_share_open(const cha= r *host, const char *port, const int max_initial_buf,
= const char *journal_dir)
{
- pid_t pid;
socke= t_descriptor_t fd[2];
struct openvpn_sockaddr hostaddr= ;
struct port_share *ps;
- int status;
- struct addrinfo *ai;

ALLOC_OBJ_CLEAR(ps, struct port_share);

ps->= foreground_fd =3D -1;
@@ -814,13 +811,15 @@
/*
* Get host's IP address
= */
-
- status =3D
- openvpn_getaddrinfo(GETADDR_RESOL= VE | GETADDR_FATAL, host, port, 0, NULL, AF_UNSPEC, &ai);
- ASSERT(status =3D=3D 0);=
- ASSERT(sizeof(hostaddr.a= ddr) >=3D ai->ai_addrlen);
- memcpy(&hostaddr.addr.sa, ai->ai_addr, ai->ai_addr= len);
- freeaddrinfo= (ai);
+ {+ struct addrinfo *ai;=
+ int status = =3D
+ open= vpn_getaddrinfo(GETADDR_RESOLVE | GETADDR_FATAL, host, port, 0, NULL, AF_UN= SPEC, &ai);
+ = ASSERT(status =3D=3D 0);
+ ASSERT(sizeof(hostaddr.addr) >=3D ai->ai_addrlen);
+ memcpy(&h= ostaddr.addr.sa, ai->ai_addr, ai->ai_addrlen);
+ freeaddrinfo(ai);
+ }


<= span> if (msg_test(D_PS_PROXY_DEBUG))
{
= @@ -836,19 +835,22 @@
*/
i= f (socketpair(PF_UNIX, SOCK_DGRAM, 0, fd) =3D=3D -1)
{=
- msg(M_WARN, &= quot;PORT SHARE: socketpair call failed");
+ msg(M_WARN | M_ERRNO, "PORT SHARE:= socketpair call failed");
goto error;=
}

/*
= * Fork off background proxy process.
*/<= br>- pid =3D fork();+ pid_t pid =3D fork();


- if = (pid)
+ if (pid &l= t; 0)
{
- int status;
-
+ msg(M_= WARN | M_ERRNO, "PORT SHARE: fork failed");
+ goto error;
+ }
+ else if (pid)
+ {
/*
= * Foreground Process
*/
@@ -86= 2,7 +864,7 @@
set_cloexec(fd[0]);
=
/* wait for background child process to initiali= ze */
- status = =3D recv_control(fd[0]);
+ int status =3D recv_control(fd[0]);
i= f (status =3D=3D RESPONSE_INIT_SUCCEEDED)
{=
/* note that this will cause possible EAGAIN when wr= iting to

To view, visit change 1470. To uns= ubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I5eac1b31ae40eb957e2c12ca6c3= 7b491fef32847
Gerrit-Change-Number: 1470
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...>
= --4r7deCSlhd0=--