From: "cron2 (Code Review)" Date: Sat, 24 Jan 2026 14:55:57 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <02112cd5e273f3e8f2a13080966468aa6481f55a-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="h/jTo9D+izU="; 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: flichtenheld Cc: plaisthos , openvpn-devel --h/jTo9D+izU= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/14= 70?usp=3Demail ) 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 Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1470 Message-Id: <20260119171216.6100-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg35= 337.html Signed-off-by: Gert Doering --- M src/openvpn/ps.c 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/openvpn/ps.c b/src/openvpn/ps.c index ed2d5c9f..e4c5794 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,9 +811,9 @@ /* * Get host's IP address */ - - status =3D - openvpn_getaddrinfo(GETADDR_RESOLVE | GETADDR_FATAL, host, port, 0= , NULL, AF_UNSPEC, &ai); + struct addrinfo *ai; + int status =3D openvpn_getaddrinfo(GETADDR_RESOLVE | GETADDR_FATAL, ho= st, 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); @@ -836,19 +833,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 +862,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: merged Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I5eac1b31ae40eb957e2c12ca6c37b491fef32847 Gerrit-Change-Number: 1470 Gerrit-PatchSet: 3 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel --h/jTo9D+izU= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 sub= mitted this change.

View Change

port-share: Check return value of fork()

= While here, do some small C11 code cleanup.

Reported-By: Joshua Roge= rs <contact@...2949...>
Found-By: ZeroPath (https://zeropath.com)<= br>Github: openvpn-private-issues#12
Change-Id: I5eac1b31ae40eb957e2c12c= a6c37b491fef32847
Signed-off-by: Frank Lichtenheld <frank@...2641...&= gt;
Acked-by: Gert Doering <gert@...1296...>
Gerrit URL: https:= //gerrit.openvpn.net/c/openvpn/+/1470
Message-Id: <20260119171216.610= 0-1-gert@...1296...>
URL: https://www.mail-archive.com/openvpn-devel@= lists.sourceforge.net/msg35337.html
Signed-off-by: Gert Doering <gert= @...1296...>
---
M src/openvpn/ps.c
1 file changed, 12 insertio= ns(+), 12 deletions(-)

diff --git a/src/openvpn/ps.c b/src/openvpn/ps.c
index e= d2d5c9f..e4c5794 100644
--- a/src/openvpn/ps.c
+++ b/src/openvpn/ps.c
@@ -800,12 +800,9 @@
<= span> port_share_open(const char *host, const char *port, const int max_ini= tial_buf,
const char *journal_dir)<= br> {
- pid_t = pid;
socket_descriptor_t fd[2];
s= truct openvpn_sockaddr hostaddr;
struct port_share *ps= ;
- int status;
- struct addrinfo *ai;

ALLOC_OBJ_CLEAR(ps, struct port_share= );
ps->foreground_fd =3D -1;
@@ -81= 4,9 +811,9 @@
/*
* Get host'= s IP address
*/
-
- s= tatus =3D
- open= vpn_getaddrinfo(GETADDR_RESOLVE | GETADDR_FATAL, host, port, 0, NULL, AF_UN= SPEC, &ai);
+ = struct addrinfo *ai;
= + int status =3D openvpn_getaddrinfo(GETADDR_RESOLVE | GETADDR_FATAL, ho= st, port,
+ = 0, NULL, AF_UNSPEC, &ai);
= ASSERT(status =3D=3D 0);
ASSERT(sizeof(hostaddr.add= r) >=3D ai->ai_addrlen);
memcpy(&hostaddr.ad= dr.sa, ai->ai_addr, ai->ai_addrlen);
@@ -836,19 +833,= 22 @@
*/
if (socketpair(PF_UNIX,= SOCK_DGRAM, 0, fd) =3D=3D -1)
{
- msg(M_WARN, "PORT SHARE: socke= tpair call failed");
+ msg(M_WARN | M_ERRNO, "PORT SHARE: socketpair call faile= d");
goto error;
}

/*
* Fork off backg= round proxy process.
*/
- pid =3D fork();
+ pid_t pid =3D fork();
<= br>- if (pid)
+ if (pid < 0)
= {
- int sta= tus;
-
+ msg(M_WARN | M_ERRNO, "= PORT SHARE: fork failed");
+ goto error;
+ }
+ = else if (pid)
+ = {
/*
* Foreground Proces= s
*/
@@ -862,7 +862,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 RESPON= SE_INIT_SUCCEEDED)
{
= /* note that this will cause possible EAGAIN when writing to

To view, visit change 1470. To unsubscribe, or for help w= riting mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I5eac1b31ae40eb957e2c12ca6c3= 7b491fef32847
Gerrit-Change-Number: 1470
Gerrit-PatchSet: 3
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --h/jTo9D+izU=--