Package: libssh-2
Version: 0.2+svn20070321-4

libssh's known host parsing is very limited, it just checks for the
hostname as the first part of a line before a ',' and nothing else.

Not even for alternate names (distributed known hosts files usually
have one line per host with all the names (including the differently
qualified variants) of it separated with ',', which the attached patch
fixes (though I really suggest someone should take a look at what ssh
supports and implement that, especially the hashed hostnames or the new
possibility to add port information.

Hochachtungsvoll,
        Bernhard R. Link
Index: libssh-0.2+svn20070321/libssh/keyfiles.c
===================================================================
--- libssh-0.2+svn20070321.orig/libssh/keyfiles.c       2008-02-24 
13:57:55.000000000 +0100
+++ libssh-0.2+svn20070321/libssh/keyfiles.c    2008-02-24 14:03:58.000000000 
+0100
@@ -795,15 +795,19 @@
             ptr++; /* skip the initial spaces */
         /* we allow spaces or ',' to follow the hostname. It's generaly an IP 
*/
         /* we don't care about ip, if the host key match there is no problem 
with ip */
-        if(strncasecmp(ptr,hostname,strlen(hostname))==0){
-            if(ptr[strlen(hostname)]==' ' || ptr[strlen(hostname)]=='\0' 
-                    || ptr[strlen(hostname)]==','){
-                if(strcasecmp(found_type, type)==0){
-                    fclose(file);
-                    return tokens;
-                } else {
-                    ret=FOUND_OTHER;
-                }
+       while(*ptr!=' ' && *ptr!='\0') {
+            if(strncasecmp(ptr,hostname,strlen(hostname))==0 &&
+                (ptr[strlen(hostname)]==' ' || ptr[strlen(hostname)]=='\0'
+                        || ptr[strlen(hostname)]==',')){
+                    if(strcasecmp(found_type, type)==0){
+                        fclose(file);
+                        return tokens;
+                    } else {
+                        ret=FOUND_OTHER;
+                    }
+            } else {
+                while(*ptr!='\0' && *ptr!=' ' && *ptr!=',')
+                    ptr++;
             }
         }
         /* not the good one */

Reply via email to