From 4b38c5ea8b261eed4f68751cc345e9a24e392ad8 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 22 Jul 2013 07:11:35 +0000 Subject: [PATCH] Rework keylist_update() to fix both a buffer-size limitation and a memory leak. git-svn-id: svn://svn.tartarus.org/sgt/putty@9955 cda61777-01e9-0310-a592-d414129be87e --- windows/winpgnt.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/windows/winpgnt.c b/windows/winpgnt.c index e0181599..e220d6bb 100644 --- a/windows/winpgnt.c +++ b/windows/winpgnt.c @@ -353,28 +353,27 @@ static void keylist_update(void) 0, (LPARAM) listentry); } for (i = 0; NULL != (skey = index234(ssh2keys, i)); i++) { - char listentry[512], *p; - int len; + char *listentry, *p; + int fp_len; /* * Replace two spaces in the fingerprint with tabs, for * nice alignment in the box. */ p = skey->alg->fingerprint(skey->data); - strncpy(listentry, p, sizeof(listentry)); + listentry = dupprintf("%s\t%s", p, skey->comment); + fp_len = strlen(listentry); + sfree(p); + p = strchr(listentry, ' '); - if (p) + if (p && p < listentry + fp_len) *p = '\t'; p = strchr(listentry, ' '); - if (p) + if (p && p < listentry + fp_len) *p = '\t'; - len = strlen(listentry); - if (len < sizeof(listentry) - 2) { - listentry[len] = '\t'; - strncpy(listentry + len + 1, skey->comment, - sizeof(listentry) - len - 1); - } + SendDlgItemMessage(keylist, 100, LB_ADDSTRING, 0, (LPARAM) listentry); + sfree(listentry); } SendDlgItemMessage(keylist, 100, LB_SETCURSEL, (WPARAM) - 1, 0); } -- 2.11.0