From: "selvanair (Code Review)" Date: Mon, 27 Apr 2026 20:52:02 +0000 In-Reply-To: References: Reply-To: selva.nair@...277..., 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="5bO+Q4pqZ1Y="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Avoid recursive call of man_read List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --5bO+Q4pqZ1Y= 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 reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1639?usp=3Demail to look at the new patch set (#2). The following approvals got outdated and were removed: Code-Review+1 by plaisthos Change subject: Avoid recursive call of man_read ...................................................................... Avoid recursive call of man_read Recursion to `man_read()` happens on Windows when `man_process_command` tries to log the received command because `management_io` first checks FD_READ and calls `man_read()` again if there is data is pending in the receive buffer. This is buggy as `man_read()` is not designed to be re-entrant. Fix this by disallowing recursion -- just return 0 so that managament_io will complete without recursion. Check this condition and do not clear FD_READ from the event mask in management_io when man_read returns without calling recv(). Read will get serviced next time when the main even= t loop calls `management_io` thorugh `process_io`. Note that `management_io` always calls `reset_net_event_win32()` (manage.c: 3298) which will pickup if any new data to read is pending (win32.c: 357) as well as retain FD_READ= if already set. Giithub: Fixes OpenVPN/openvpn#1023 Change-Id: I9433baee1f5a66d43d4e43e03128ae6a790a7937 Signed-off-by: Selva Nair --- M src/openvpn/manage.c M src/openvpn/manage.h 2 files changed, 16 insertions(+), 2 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/39/1639/2 diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c index 2a3023c..31c4bb5 100644 --- a/src/openvpn/manage.c +++ b/src/openvpn/manage.c @@ -2426,6 +2426,12 @@ unsigned char buf[256]; ssize_t len =3D 0; + if (man->connection.man_read_state !=3D MAN_READ_IDLE) + { + return 0; /* not ready to read now */ + } + man->connection.man_read_state =3D MAN_READ_ACTIVE; + #ifdef TARGET_ANDROID int fd; len =3D man_recv_with_fd(man->connection.sd_cli, buf, sizeof(buf), MSG= _NOSIGNAL, &fd); @@ -2508,6 +2514,7 @@ man_reset_client_socket(man, false); } } + man->connection.man_read_state =3D MAN_READ_IDLE; return len; } @@ -3309,10 +3316,14 @@ { if (net_events & FD_READ) { - while (man_read(man) > 0) + if (man->connection.man_read_state =3D=3D MAN_READ_IDL= E) { + while (man_read(man) > 0) + { + } + net_event_win32_clear_selected_events(&man->connec= tion.ne32, FD_READ); } - net_event_win32_clear_selected_events(&man->connection= .ne32, FD_READ); + /* if ACTIVE: reentrancy, skip read and skip clearing = FD_READ */ } if (net_events & FD_WRITE) diff --git a/src/openvpn/manage.h b/src/openvpn/manage.h index 27d3b60..0632500 100644 --- a/src/openvpn/manage.h +++ b/src/openvpn/manage.h @@ -328,6 +328,9 @@ int lastfdreceived; #endif int client_version; +#define MAN_READ_IDLE 0 +#define MAN_READ_ACTIVE 1 + int man_read_state; }; struct management -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1639?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I9433baee1f5a66d43d4e43e03128ae6a790a7937 Gerrit-Change-Number: 1639 Gerrit-PatchSet: 2 Gerrit-Owner: selvanair Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos --5bO+Q4pqZ1Y= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: plaisthos.

selvanair uploaded patch set #2 to this change.

<= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/1639?usp=3Demail">View Chan= ge

The following approvals got outdated and were removed: Code-Review+1 by plaisthos

Avoid recursive call of man_rea=
d

Recursion to `man_read()` happens on Windows when `man_process_com= mand`
tries to log the received command because `management_io`
first= checks FD_READ and calls `man_read()` again if there is data is
pending= in the receive buffer. This is buggy as `man_read()` is not
designed to= be re-entrant.

Fix this by disallowing recursion -- just return 0 s= o that managament_io
will complete without recursion. Check this conditi= on and do not clear
FD_READ from the event mask in management_io when ma= n_read returns
without calling recv(). Read will get serviced next time = when the main event loop
calls `management_io` thorugh `process_io`. No= te that `management_io`
always calls `reset_net_event_win32()` (manage.c= : 3298) which will pickup
if any new data to read is pending (win32.c: 3= 57) as well as retain FD_READ if
already set.

Giithub: Fixes Open= VPN/openvpn#1023

Change-Id: I9433baee1f5a66d43d4e43e03128ae6a790a793= 7
Signed-off-by: Selva Nair <selva.nair@...277...>
---
M src= /openvpn/manage.c
M src/openvpn/manage.h
2 files changed, 16 insertio= ns(+), 2 deletions(-)

git pull ssh://gerrit.open=
vpn.net:29418/openvpn refs/changes/39/1639/2
diff --git a/src/openv=
pn/manage.c b/src/openvpn/manage.c
index 2a3023c..31c4bb5 1= 00644
--- a/src/openvpn/manage.c
+++ b/src/= openvpn/manage.c
@@ -2426,6 +2426,12 @@
= unsigned char buf[256];
ssize_t len =3D 0;
+ if (man= ->connection.man_read_state !=3D MAN_READ_IDLE)
+ {
+ return 0; /* not ready to read now */
+ }
+ man->connection.man_read_state =3D MAN_= READ_ACTIVE;
+=
#ifdef TARGET_ANDROID
int fd;
len =3D man_recv_with_fd(man->connection.sd_cli, buf, sizeof(buf= ), MSG_NOSIGNAL, &fd);
@@ -2508,6 +2514,7 @@
= man_reset_client_socket(man, false);
= }
}
+ man->connection.man_read_state =3D MAN_READ_IDLE;<= br> return len;
}

@@ -3309,10 +3316,14 @@
{
= if (net_events & FD_READ)
= {
- = while (man_read(man) > 0)
+ if (man->connection.man_read_state =3D= =3D MAN_READ_IDLE)
{
+ while (man_re= ad(man) > 0)
+ = {
+ }
+ net_event_win32_clear_selected_events(&= man->connection.ne32, FD_READ);
}
- net= _event_win32_clear_selected_events(&man->connection.ne32, FD_READ);<= /span>
+ = /* if ACTIVE: reentrancy, skip read and skip clearing FD_READ */
= }

= if (net_events & FD_WRITE)
diff --git a/src/openvpn/ma= nage.h b/src/openvpn/manage.h
index 27d3b60..0632500 100644=
--- a/src/openvpn/manage.h
+++ b/src/openv= pn/manage.h
@@ -328,6 +328,9 @@
int la= stfdreceived;
#endif
int client_versi= on;
+#define MAN_READ= _IDLE 0
+#define MA= N_READ_ACTIVE 1
+ = int man_read_state;
};

= struct management

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

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I9433baee1f5a66d43d4e43e0312= 8ae6a790a7937
Gerrit-Change-Number: 1639
Gerrit-PatchSet: 2
Gerrit-Owner: selvanair <selva.nair@...1354...= ..>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
= --5bO+Q4pqZ1Y=--