From 9934e1c9b838994bf0604a988c54d0e7b8d315ae Mon Sep 17 00:00:00 2001 From: saravanank Date: Thu, 26 Mar 2020 17:36:37 -0700 Subject: [PATCH] vtysh: Crash during show running-config RCA: when client is killed, show running-config command crashes vtysh. vtysh_client_config function temporarily makes vty->of which is standard output file pointer to null inorder to suppress output to user. This call further tries to communicate with each client and when the client is terminated, socket call fails and hits the exception path to print the connection has failed using vty_out. vty_out crashes because vtysh_client_config has temporarily made vty->of pointer to NULL to supress o/p to user. Fix: vty_out function should check for the sanity of vty->of pointer. If it doesn't exist, this must have hit exception path, so use the vty->saved_of if exists. Signed-off-by: Saravanan K --- lib/vty.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/vty.c b/lib/vty.c index 4dd6ec1b35..8056236de9 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -231,8 +231,13 @@ int vty_out(struct vty *vty, const char *format, ...) strlen(filtered)); break; case VTY_SHELL: - fprintf(vty->of, "%s", filtered); - fflush(vty->of); + if (vty->of) { + fprintf(vty->of, "%s", filtered); + fflush(vty->of); + } else if (vty->of_saved) { + fprintf(vty->of_saved, "%s", filtered); + fflush(vty->of_saved); + } break; case VTY_SHELL_SERV: case VTY_FILE: