diff cli-main.c @ 1065:23103e1e9548

Fix error handling for dbclient async connect
author Matt Johnston <matt@ucc.asn.au>
date Tue, 03 Mar 2015 20:53:00 +0800
parents 0da8ba489c23
children fb58cf341951
line wrap: on
line diff
--- a/cli-main.c	Mon Mar 02 21:40:06 2015 +0800
+++ b/cli-main.c	Tue Mar 03 20:53:00 2015 +0800
@@ -87,6 +87,7 @@
 static void cli_dropbear_exit(int exitcode, const char* format, va_list param) {
 
 	char fmtbuf[300];
+	char exitmsg[500];
 
 	if (!sessinitdone) {
 		snprintf(fmtbuf, sizeof(fmtbuf), "Exited: %s",
@@ -98,12 +99,15 @@
 				cli_opts.remoteport, format);
 	}
 
+	/* Arguments to the exit printout may be unsafe to use after session_cleanup() */
+	vsnprintf(exitmsg, sizeof(exitmsg), fmtbuf, param);
+
 	/* Do the cleanup first, since then the terminal will be reset */
 	session_cleanup();
 	/* Avoid printing onwards from terminal cruft */
 	fprintf(stderr, "\n");
 
-	_dropbear_log(LOG_INFO, fmtbuf, param);
+	dropbear_log(LOG_INFO, "%s", exitmsg);;
 	exit(exitcode);
 }