From f8fe48e7fb2f0fef722bcd0d4cf37f6697ae86b4 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Fri, 30 Aug 2019 00:15:26 +0200 Subject: fix: vty crash by logging during VTY_CLOSED event handling When a VTY closes, dispatch the VTY_CLOSED signal before tearing down the VTY buffer and fd. In particular this fixes: - a crash during telnet_close_client(), invoked by the VTY_CLOSED event, which logs to DLGLOBAL and uses vty->obuf that, so far, vty_close() had already unallocated earlier (OS#4164). - the logging about closing a telnet session so far logged: DLGLOBAL INFO Closing telnet connection r=NULL<->l=NULL By dispatching the VTY_CLOSED event while the fd is still valid, we instead get the actual connection IP address and port being closed: DLGLOBAL INFO Closing telnet connection r=127.0.0.1:36708<->l=127.0.0.1:4258 Related: OS#4164 Change-Id: I1d235cbfbfb9aaf411316642c7bcfac12106df44 --- src/vty/vty.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/vty/vty.c b/src/vty/vty.c index a96d86ce..aa23fa00 100644 --- a/src/vty/vty.c +++ b/src/vty/vty.c @@ -205,6 +205,9 @@ void vty_close(struct vty *vty) { int i; + /* VTY_CLOSED is handled by the telnet_interface */ + vty_event(VTY_CLOSED, vty->fd, vty); + if (vty->obuf) { /* Flush buffer. */ buffer_flush_all(vty->obuf, vty->fd); @@ -236,9 +239,6 @@ void vty_close(struct vty *vty) /* Check configure. */ vty_config_unlock(vty); - /* VTY_CLOSED is handled by the telnet_interface */ - vty_event(VTY_CLOSED, vty->fd, vty); - /* OK free vty. */ talloc_free(vty); } -- cgit v1.2.3