Subject: Re: Problem with known_hosts

Re: Problem with known_hosts

From: Alexander Lamaison <swish_at_lammy.co.uk>
Date: Mon, 7 Mar 2011 02:11:19 +0000

On 3 March 2011 15:33, Pierre-Yves Fontaniere <pyf_at_cc.in2p3.fr> wrote:
> On 03/03/2011 03:04 PM, Alexander Lamaison wrote:
>>
>> On 2 March 2011 15:22, Pierre-Yves Fontaniere<pyf_at_cc.in2p3.fr>  wrote:
>>>
>>>  - Some lines to really remove ending '\n' directly when reading lines
>>> from
>>> knownhosts file.
>>>
>>
>> Can you explain a bit more about this?  What was the code doing wrong
>> before?
>>
>
> In fact, the code wasn't doing something wrong. But when i was debugging, i
> saw (with simple printf) keys with leading '\n'. So I thought first the
> problem was here. I saw later that was not the case but even if i know that
> there's no use of function like strlen in the code, i prefer having a '\n'
> leading free and zero terminated string.

I still don't understand what you mean. Where are you seeing these
leading '\n's? The existing code extracts the key from the file
without including any '\n'. What has strlen got to do with it?

> libssh2_knownhost_readfile is the only place where we use something else
> than const char *. So this is the place to format every line and have zero
> terminated string without leading '\n'.

I'm lost. What is the relevance of const char*?
libssh2_knownhost_readline doesn't change the contents of the line so
it doesn't matter that it's const char*.

> I used strrchr which take the buffer from the end and doesn't browse all the
> key from the beginning (like it is done later in
> libssh2_knownhost_readline).

Your code tries to replace '\n' with '\0' before reading the entry but
this isn't necessary as hostline takes a key and a keylength. It
doesn't treat the key as a terminated string. You can terminate it
with anything you like and, as long as the length is correct, it will
work.

> I let you decide if it is an interesting modification or not. :)

I'm afraid not. It does extra work and breaks the behaviour of
libssh2_knownhost_readline, a public API function. When passed a line
that ends in '\n', libssh2_knownhost_readline now adds the key to the
collection with the newline still present. This is wrong.

>> For my testing, can you send me an example of what one of these AIX
>> entries with multiple aliases contains?
>>
>
> This is not specific to AIX :) we use this kind of knownhosts entries on
> Linux, Solaris and AIX.
>
> Entry like :
>
> ccsmurf,ccsvli05,ccsvli05.in2p3.fr,ccsmurf.in2p3.fr,134.158.104.140 ssh-rsa
> AAAAB3NzaC1yc2EAAAABIwAAAIEAq1iiPKlBbyw3I+wC76ugwt7DGnseVNjzjZf8y7vO+2oiuBkRMdoqh9K3oHzkiloTeAHOZH4V89nUt/WLTqKG4j4/sSwaCD9gRKwFS4me/Pnvi8zqwmF8YrLwQdTGtDZo2iz0Dt4KqAE6fQ9mQ/iTlJMFUKOed8luDDfX6Ba0lBE=

Thanks. I will do some more testing using this entry at some point this week.

Alex

--
Swish - Easy SFTP for Windows Explorer (http://www.swish-sftp.org)
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2011-03-07