From: "selvanair (Code Review)" Date: Mon, 27 Apr 2026 17:33:25 +0000 References: Reply-To: selva.nair@...277..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <980c92a9aad69e8ae61d829218e5432dab1f198b-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="tES271nDGRQ="; charset=UTF-8 Subject: [Openvpn-devel] [XS] 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 --tES271nDGRQ= 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/+/1639?usp=3Demail to review the following change. 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. Although this will also clear FD_READ from the event mask via `net_event_win32_clear_selected_events(&man->connection.ne32, FD_READ)` (manage.c:3312), read will get serviced next time when the main event 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 data to read is pending (win32.c: 357) as FD_READ is level triggered. Giithub: Fixes OpenVPN/openvpn#1023 Change-Id: I9433baee1f5a66d43d4e43e03128ae6a790a7937 Signed-off-by: Selva Nair --- M src/openvpn/manage.c 1 file changed, 8 insertions(+), 0 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/39/1639/1 diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c index 2a3023c..4d46e61 100644 --- a/src/openvpn/manage.c +++ b/src/openvpn/manage.c @@ -2425,6 +2425,13 @@ */ unsigned char buf[256]; ssize_t len =3D 0; + static int recursive_level =3D 0; + + if (recursive_level > 0) + { + return 0; /* not ready to read now */ + } + recursive_level++; #ifdef TARGET_ANDROID int fd; @@ -2508,6 +2515,7 @@ man_reset_client_socket(man, false); } } + recursive_level--; return len; } -- 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: newchange Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I9433baee1f5a66d43d4e43e03128ae6a790a7937 Gerrit-Change-Number: 1639 Gerrit-PatchSet: 1 Gerrit-Owner: selvanair Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos --tES271nDGRQ= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: plaisthos.

selvanair would like plaisthos to review this change.

V= iew Change

Avoid recursive call of man_read

Rec= ursion to `man_read()` happens on Windows when `man_process_command`
tri= es to log the received command because `management_io`
first checks FD_R= EAD and calls `man_read()` again if there is data is
pending in the rece= ive buffer. This is buggy as `man_read()` is not
designed to be re-entra= nt.

Fix this by disallowing recursion -- just return 0 so that manag= ament_io
will complete without recursion. Although this will also clear<= br>FD_READ from the event mask via
`net_event_win32_clear_selected_e= vents(&man->connection.ne32, FD_READ)`
(manage.c:3312), read will= get serviced next time when the main event loop
calls `management_io` t= horugh `process_io`. Note that `management_io`
always calls `reset_net_= event_win32()` (manage.c: 3298) which will pickup
if any data to read is= pending (win32.c: 357) as FD_READ is level triggered.

Giithub: Fixe= s OpenVPN/openvpn#1023

Change-Id: I9433baee1f5a66d43d4e43e03128ae6a7= 90a7937
Signed-off-by: Selva Nair <selva.nair@...277...>
---M src/openvpn/manage.c
1 file changed, 8 insertions(+), 0 deletions(-)<= br>
git pull ssh://gerrit.openvpn.net:29418/openvpn =
refs/changes/39/1639/1
diff --git a/src/openvpn/manage.c b/src/open=
vpn/manage.c
index 2a3023c..4d46e61 100644
= --- a/src/openvpn/manage.c
+++ b/src/openvpn/manage.c
@@ -2425,6 +2425,13 @@
*/
= unsigned char buf[256];
ssize_t len =3D 0;=
+ static int recursive_l= evel =3D 0;
+<= br>+ if (recursive_level >= ; 0)
+ {+ return 0; /* not read= y to read now */
+ = }
+ recursive_lev= el++;

#ifdef TARGET_ANDROID
int fd;

@@ -2508,6 +2515,7 @@
= man_reset_client_socket(man, false);
}
}
= + recursive_level--;
return len;
}=


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

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I9433baee1f5a66d43d4e43e0312= 8ae6a790a7937
Gerrit-Change-Number: 1639
Gerrit-PatchSet: 1
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...>
= --tES271nDGRQ=--