summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHansH111 <hans@atbas.org>2022-03-13 17:38:13 +0000
committerHansH111 <hans@atbas.org>2022-03-13 17:38:13 +0000
commit4058d117713892dbf8efe978f0b0ea4abdcf375b (patch)
treeb848cab6f12edf2d79af1ea851a1f439f7816997
parent29805f62f5c7fca6dfca31cf243443eaebac7382 (diff)
downloaddropbear-4058d117713892dbf8efe978f0b0ea4abdcf375b.tar.gz
extract pubkey_info when seuccesfully auth with a key and free it in the cleanup function
-rw-r--r--svr-authpubkey.c23
-rw-r--r--svr-authpubkeyoptions.c3
2 files changed, 23 insertions, 3 deletions
diff --git a/svr-authpubkey.c b/svr-authpubkey.c
index a33cc39..10356a8 100644
--- a/svr-authpubkey.c
+++ b/svr-authpubkey.c
@@ -261,7 +261,7 @@ static int checkpubkey_line(buffer* line, int line_num, const char* filename,
const char* algo, unsigned int algolen,
const unsigned char* keyblob, unsigned int keybloblen) {
buffer *options_buf = NULL;
- unsigned int pos, len;
+ unsigned int pos, len, infopos, infolen;
int ret = DROPBEAR_FAILURE;
if (line->len < MIN_AUTHKEYS_LINE || line->len > MAX_AUTHKEYS_LINE) {
@@ -344,6 +344,11 @@ static int checkpubkey_line(buffer* line, int line_num, const char* filename,
for (len = 0; line->pos < line->len; len++) {
if (buf_getbyte(line) == ' ') break;
}
+ /* findout the length of the public key info */
+ infopos = line->pos;
+ for (infolen = 0; line->pos < line->len; infolen++) {
+ if (buf_getbyte(line) == ' ') break;
+ }
buf_setpos(line, pos);
buf_setlen(line, line->pos + len);
@@ -351,8 +356,20 @@ static int checkpubkey_line(buffer* line, int line_num, const char* filename,
ret = cmp_base64_key(keyblob, keybloblen, (const unsigned char *) algo, algolen, line, NULL);
- if (ret == DROPBEAR_SUCCESS && options_buf) {
- ret = svr_add_pubkey_options(options_buf, line_num, filename);
+ if (ret == DROPBEAR_SUCCESS) {
+ if (options_buf) {
+ ret = svr_add_pubkey_options(options_buf, line_num, filename);
+ }
+ /* save the (optional) public key information */
+ if (infolen) {
+ ses.authstate.pubkey_info = m_malloc(infolen + 1);
+ if (ses.authstate.pubkey_info) {
+ strncpy(ses.authstate.pubkey_info, &line->data[infopos], infolen);
+ ses.authstate.pubkey_info[infolen]='\0';
+ }
+ } else {
+ ses.authstate.pubkey_info = NULL;
+ }
}
out:
diff --git a/svr-authpubkeyoptions.c b/svr-authpubkeyoptions.c
index 7ddf680..447f4b7 100644
--- a/svr-authpubkeyoptions.c
+++ b/svr-authpubkeyoptions.c
@@ -115,6 +115,9 @@ void svr_pubkey_options_cleanup() {
}
m_free(ses.authstate.pubkey_options);
}
+ if (ses.authstate.pubkey_info) {
+ m_free(ses.authstate.pubkey_info);
+ }
}
/* helper for svr_add_pubkey_options. returns DROPBEAR_SUCCESS if the option is matched,