From ab6ea4d697d317bca4385811c26376c25bc1b91d Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Wed, 9 Nov 2022 13:10:17 +0800 Subject: [PATCH] Fix plugin argument This broke in the re-exec changes, it was altering the argv argument in-place, but argv was re-used later. Fixes #194 github issue --- runopts.h | 6 ++++-- svr-runopts.c | 18 +++++++++--------- svr-session.c | 12 +++++++----- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/runopts.h b/runopts.h index 50c51df..90b809c 100644 --- a/runopts.h +++ b/runopts.h @@ -128,8 +128,10 @@ typedef struct svr_runopts { char * forced_command; #if DROPBEAR_PLUGIN - char *pubkey_plugin; - char *pubkey_plugin_options; + /* malloced */ + char *pubkey_plugin; + /* points into pubkey_plugin */ + char *pubkey_plugin_options; #endif int pass_on_env; diff --git a/svr-runopts.c b/svr-runopts.c index c15f23b..f2e8b89 100644 --- a/svr-runopts.c +++ b/svr-runopts.c @@ -448,15 +448,15 @@ void svr_getopts(int argc, char ** argv) { #endif #if DROPBEAR_PLUGIN - if (pubkey_plugin) { - char *args = strchr(pubkey_plugin, ','); - if (args) { - *args='\0'; - ++args; - } - svr_opts.pubkey_plugin = pubkey_plugin; - svr_opts.pubkey_plugin_options = args; - } + if (pubkey_plugin) { + svr_opts.pubkey_plugin = m_strdup(pubkey_plugin); + char *args = strchr(svr_opts.pubkey_plugin, ','); + if (args) { + *args='\0'; + ++args; + } + svr_opts.pubkey_plugin_options = args; + } #endif } diff --git a/svr-session.c b/svr-session.c index dac7de2..769f073 100644 --- a/svr-session.c +++ b/svr-session.c @@ -208,7 +208,7 @@ void svr_session(int sock, int childpipe) { } -/* failure exit - format must be <= 100 chars */ +/* cleanup and exit - format must be <= 100 chars */ void svr_dropbear_exit(int exitcode, const char* format, va_list param) { char exitmsg[150]; char fullmsg[300]; @@ -217,10 +217,12 @@ void svr_dropbear_exit(int exitcode, const char* format, va_list param) { int add_delay = 0; #if DROPBEAR_PLUGIN - if ((ses.plugin_session != NULL)) { - svr_ses.plugin_instance->delete_session(ses.plugin_session); - } - ses.plugin_session = NULL; + if ((ses.plugin_session != NULL)) { + svr_ses.plugin_instance->delete_session(ses.plugin_session); + } + ses.plugin_session = NULL; + svr_opts.pubkey_plugin_options = NULL; + m_free(svr_opts.pubkey_plugin); #endif /* Render the formatted exit message */