This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new 3dd67bcf2 system/telnet: fix use-after-free in chatd DATA event handler
3dd67bcf2 is described below

commit 3dd67bcf2189aea73ca2b2605b954594d3cb4cd3
Author: zhangshuai39 <[email protected]>
AuthorDate: Fri May 29 15:24:30 2026 +0800

    system/telnet: fix use-after-free in chatd DATA event handler
    
    When a user types "quit", _online() closes the socket and calls
    telnet_free(user->telnet), but control then returns to _event_handler
    which immediately calls telnet_negotiate() on the same already-freed
    handle. Skip further negotiation when user->sock is -1 to avoid the
    use-after-free reported by KASAN/AddressSanitizer.
    
    Signed-off-by: zhangshuai39 <[email protected]>
    Assisted-by: Kiro:claude-opus-4
---
 system/telnet/telnet_chatd.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/system/telnet/telnet_chatd.c b/system/telnet/telnet_chatd.c
index d7bab4554..f956cd15c 100644
--- a/system/telnet/telnet_chatd.c
+++ b/system/telnet/telnet_chatd.c
@@ -306,6 +306,18 @@ static void _event_handler(struct telnet_s *telnet,
 
       case TELNET_EV_DATA:
         _input(user, ev->data.buffer, ev->data.size);
+
+        /* _input -> _online may have processed a "quit" command which
+         * closes the socket and frees user->telnet.  Accessing the freed
+         * telnet handle below would then be a use-after-free, so skip the
+         * negotiation once the user has been torn down.
+         */
+
+        if (user->sock == -1)
+          {
+            break;
+          }
+
         telnet_negotiate(telnet, TELNET_WONT, TELNET_TELOPT_ECHO);
         telnet_negotiate(telnet, TELNET_WILL, TELNET_TELOPT_ECHO);
         break;

Reply via email to