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
diff --git a/src/vty/vty.c b/src/vty/vty.c
index a96d86c..aa23fa0 100644
--- a/src/vty/vty.c
+++ b/src/vty/vty.c
@@ -205,6 +205,9 @@
{
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 @@
/* 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);
}