From 909a7af07c2410f454245f42bad67ec5b1096f84 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 27 Mar 2016 14:59:18 +0100 Subject: [PATCH] Fix assertion failure in host keys log message. When Jacob introduced this message in d0d3c47a0, he was right to assume that hostkey_algs[] and ssh->uncert_hostkeys[] were sorted in the same order. Unfortunately, he became wrong less than an hour later when I committed d06098622. Now we avoid making any such assumption. --- ssh.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/ssh.c b/ssh.c index c5e5993c..a94ebd41 100644 --- a/ssh.c +++ b/ssh.c @@ -7256,12 +7256,17 @@ static void do_ssh2_transport(Ssh ssh, const void *vin, int inlen, * Make a note of any other host key formats that are available. */ { - int i, j = 0; + int i, j; char *list = NULL; for (i = 0; i < lenof(hostkey_algs); i++) { if (hostkey_algs[i].alg == ssh->hostkey) continue; - else if (ssh->uncert_hostkeys[j] == i) { + + for (j = 0; j < ssh->n_uncert_hostkeys; j++) + if (ssh->uncert_hostkeys[j] == i) + break; + + if (j < ssh->n_uncert_hostkeys) { char *newlist; if (list) newlist = dupprintf("%s/%s", list, @@ -7270,14 +7275,6 @@ static void do_ssh2_transport(Ssh ssh, const void *vin, int inlen, newlist = dupprintf("%s", hostkey_algs[i].alg->name); sfree(list); list = newlist; - j++; - /* Assumes that hostkey_algs and uncert_hostkeys are - * sorted in the same order */ - if (j == ssh->n_uncert_hostkeys) - break; - else - assert(ssh->uncert_hostkeys[j] > - ssh->uncert_hostkeys[j-1]); } } if (list) {