]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
rpc: libssh2: Fix regression in ssh host key verification
authorPeter Krempa <pkrempa@redhat.com>
Fri, 2 Oct 2015 13:49:01 +0000 (15:49 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 5 Oct 2015 05:38:18 +0000 (07:38 +0200)
Commit 792f81a40e caused a regression in the libssh2 host key
verification code by changing the variable type of 'i' to unsigned.
Since one of the loops used -1 as a special value if the asking
callback was found the conversion made a subsequent test always fail.

The bug was stealth enough to pass review, compilers and coverity.

Refactor the condition to avoid problems.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1047861

src/rpc/virnetsshsession.c

index becdf6e8479265bc2488d5f45d2f1eabd4ac2d95..406a8314b5fedf25f1df7c6cf6eada2780f79771 100644 (file)
@@ -344,16 +344,14 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess)
             memset(&askKey, 0, sizeof(virConnectCredential));
 
             for (i = 0; i < sess->cred->ncredtype; i++) {
-                if (sess->cred->credtype[i] == VIR_CRED_ECHOPROMPT) {
-                    i = -1;
+                if (sess->cred->credtype[i] == VIR_CRED_ECHOPROMPT)
                     break;
-                }
             }
 
-            if (i > 0) {
+            if (i == sess->cred->ncredtype) {
                 virReportError(VIR_ERR_SSH, "%s",
-                               _("no suitable method to retrieve "
-                                 "authentication credentials"));
+                               _("no suitable callback for host key "
+                                 "verification"));
                 return -1;
             }