T207: move ssh_key_dup() from pki.h to libssh.h?
Description
Originally reported by ZhaoGuangYue1986: https://bugs.libssh.org/T207
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
Comments:
Jakuje commented on 2019-12-15 09:04:59 UTC:
What is the use case where you needed the ssh_key_dup()?
ZhaoGuangYue1986 commented on 2019-12-15 10:13:53 UTC:
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
Jakuje commented on 2019-12-15 10:35:46 UTC:
! In T207#3529, @ZhaoGuangYue1986 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).
ZhaoGuangYue1986 commented on 2019-12-15 10:54:34 UTC:
! In T207#3531, @Jakuje wrote:
! In T207#3529, @ZhaoGuangYue1986 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