]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Fix assertion failure in host keys log message.
authorSimon Tatham <anakin@pobox.com>
Sun, 27 Mar 2016 13:59:18 +0000 (14:59 +0100)
committerSimon Tatham <anakin@pobox.com>
Sun, 27 Mar 2016 13:59:18 +0000 (14:59 +0100)
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

diff --git a/ssh.c b/ssh.c
index c5e5993c253e4634c0b7c0c02bafc3cc2fe16dff..a94ebd4110f058c42a6da885b9ca792415f860c5 100644 (file)
--- 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) {