Subject: Re: libssh2 master 164838c sftp_readdir: return error if buffer is too small

Re: libssh2 master 164838c sftp_readdir: return error if buffer is too small

From: Alexander Lamaison <swish_at_lammy.co.uk>
Date: Tue, 4 Jan 2011 14:14:48 +0000

Sorry. Not the world's clearest explanation, I grant you.

libssh2 has the actual lengths of the filename and longentry available
(it computes them during the call and stores them in filename_len and
longentry_len) but it doesn't expose them to the caller. The caller
blindly provides a buffer of a certain length and just has to hope
this does the trick. Instead we could add another API function
(sftp_readdir_lengths?) which only does the length computations and
returns these. Then the caller allocates buffers of those lengths and
calls sftp_readdir as usual but without the risk of a BUFFER_TOO_SMALL
error.

A different strategy found in the Windows API is to use a single API
function but if the first call to it uses too small a buffer it
returns the required size as the error value. The caller can then fix
the size of the buffer and call it again. However, I don't think this
alternative fits well with the libssh2 norm of returning a simple
error code.

Alex

--
Swish - Easy SFTP for Windows Explorer (http://www.swish-sftp.org)
On 4 January 2011 13:57, Peter Stuge <peter_at_stuge.se> wrote:
> Alexander Lamaison wrote:
>> >    sftp_readdir: return error if buffer is too small
>>
>> As libssh2 knows the length the buffer needs to be in each case, could
>> we add a separate API call that fetches this buffer size?  This would
>> allow very careful code to avoid the buffer length problem entirely.
>
> Sorry, I don't understand what you mean here. Could you elaborate a
> little?
>
>
> Thanks!
>
> //Peter
> _______________________________________________
> libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
>
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2011-01-04