1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-09-10 02:09:25 +03:00

log: fixes legacy fallback for multiple sessions.

Legacy code in 'ssh_set_callbacks' will fallback to
'ssh_legacy_log_callback' (if the current log cb is
NULL) setting the user data to the current session.

However, if any other session is created afterwards,
it won't update the user data with the new session,
potentially leading to a use-after-free.

Fixes #238.

Signed-off-by: Diego Roux <diegoroux04@protonmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
Diego Roux
2024-03-27 14:31:11 +00:00
committed by Jakub Jelen
parent 3227a4cae0
commit 46a28cfc49
6 changed files with 108 additions and 10 deletions

View File

@@ -45,6 +45,15 @@ static void ssh_legacy_log_callback(int priority,
log_fn(session, priority, buffer, log_data);
}
void
_ssh_remove_legacy_log_cb(void)
{
if (ssh_get_log_callback() == ssh_legacy_log_callback) {
_ssh_reset_log_cb();
ssh_set_log_userdata(NULL);
}
}
int ssh_set_callbacks(ssh_session session, ssh_callbacks cb) {
if (session == NULL || cb == NULL) {
return SSH_ERROR;