Subject: Re: [PATCH] add function libssh2_session_set_last_error

Re: [PATCH] add function libssh2_session_set_last_error

From: Salvador Fandino <sfandino_at_gmail.com>
Date: Thu, 22 Oct 2015 10:47:11 +0200

On 10/19/2015 01:50 PM, Kamil Dudka wrote:
> On Thursday 15 October 2015 17:57:03 Salvador Fandino wrote:
>> See the patch attached.
>>
>> It just exposes _libssh2_error through the API and its immediate
>> objective is making my life (as the current maintainer of Net::SSH2)
>> much much much easier.
>>
>> But actually, this function may be useful to anybody building new
>> features on top of the library and obviously for other wrapping modules.
>
> Thanks for the patch! I agree that it as a valid reason for extending
> the API. Nevertheless, the proposed API looks fragile to me. libssh2
> does not copy the error message to its own memory. So it is caller's
> responsibility to keep the string valid long enough. This could cause
> problems.
>
> We should either change the code to allocate memory for the error message
> or clearly specify in the API documentation for how long the string needs
> to remain valid.

Two new patches are attached.

As I didn't want to penalize every calls to "_libssh2_error" with a
"strdup", I converted it into "_libssh2_error_flags" which accepts a
flag indicating whether the given string must be duplicated and then
added a new "_libssh2_error" that just calls "_libssh2_error_flags".

Finally, the second patch adds "libssh2_session_set_last_error" to the
public API. It relies on "_libssh2_error_flags" and always duplicates
the given string.

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel

Received on 2015-10-22