Page MenuHomePhabricator

move ssh_key_dup() from pki.h to libssh.h?
Open, Needs TriagePublic

Description

ssh_key ssh_key_dup(const ssh_key key);

Hi,recently i want to use ssh_key_dup() to duplicate a ssh key ,and i found it can not be include it as it not in libssh.h, so i wonder if this funtion can be moved to libssh.h as an SSHAPI

Thanks

Event Timeline

ZhaoGuangYue1986 renamed this task from remove ssh_key_dup() from pki.h to libssh.h? to move ssh_key_dup() from pki.h to libssh.h?.Dec 15 2019, 2:06 AM
ZhaoGuangYue1986 updated the task description. (Show Details)
Jakuje added a subscriber: Jakuje.Dec 15 2019, 10:04 AM

What is the use case where you needed the ssh_key_dup()?

This issue is relatate to https://bugs.libssh.org/T206

When i use ssh_bind_options_set() with parameter SSH_BIND_OPTIONS_IMPORT_KEY , I found ssh_bind_options_set() does not duplicate the key,if i free ssh_bind ,the key also be freed but key pointer outside not set to null, in this case ,if i use the ssh_key which is freed for another bind, it wil be failed.

So i asked these two questions (T206,T207),wonder if ssh_bind_options_set can duplicate ssh key or can ssh_key_dup() move to libssh.h for API.

To my opinion, even we move ssh_key_dup() to libssh.h ,we also should duplicate ssh_key in function ssh_bind_options_set() , it is better to free memory apply by itself , not free memory applied by others

thanks

To my opinion, even we move ssh_key_dup() to libssh.h ,we also should duplicate ssh_key in function ssh_bind_options_set() , it is better to free memory apply by itself , not free memory applied by others

This would be changing behavior so for any program written with older libssh, new versions would leak this memory, because they would be expecting it will be freed with the bind. So better solution would really be to use the ssh_key_dup() yourself (easiest by including the pki.h yourself for now as suggested in the other issue).

In T207#3531, @Jakuje wrote:

To my opinion, even we move ssh_key_dup() to libssh.h ,we also should duplicate ssh_key in function ssh_bind_options_set() , it is better to free memory apply by itself , not free memory applied by others

This would be changing behavior so for any program written with older libssh, new versions would leak this memory, because they would be expecting it will be freed with the bind. So better solution would really be to use the ssh_key_dup() yourself (easiest by including the pki.h yourself for now as suggested in the other issue).

OK.
But this mean we should move ssh_key_dup() to libssh.h as a api, as applications only can reference to libssh.h , can not see pki.h

Thanks