1
1

Always check return value of ssh_list_new()

Another item identified during code review was cases where the return
value of ssh_list_new() was not properly checked and handled. This
updates all cases that were missing this to handle failure to allocate a
new list.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Этот коммит содержится в:
Dirkjan Bussink 2020-12-10 14:14:11 +00:00 коммит произвёл Andreas Schneider
родитель daeee74edd
Коммит 0987e6065c
5 изменённых файлов: 42 добавлений и 21 удалений

Просмотреть файл

@ -117,6 +117,13 @@ ssh_channel ssh_channel_new(ssh_session session)
if (session->channels == NULL) {
session->channels = ssh_list_new();
if (session->channels == NULL) {
ssh_set_error_oom(session);
SSH_BUFFER_FREE(channel->stdout_buffer);
SSH_BUFFER_FREE(channel->stderr_buffer);
SAFE_FREE(channel);
return NULL;
}
}
ssh_list_prepend(session->channels, channel);

Просмотреть файл

@ -372,6 +372,7 @@ struct ssh_list *ssh_known_hosts_get_algorithms(ssh_session session)
list = ssh_list_new();
if (list == NULL) {
ssh_set_error_oom(session);
SAFE_FREE(host_port);
return NULL;
}

Просмотреть файл

@ -513,24 +513,30 @@ static int ssh_message_termination(void *s){
* @warning This function blocks until a message has been received. Betterset up
* a callback if this behavior is unwanted.
*/
ssh_message ssh_message_get(ssh_session session) {
ssh_message msg = NULL;
int rc;
ssh_message ssh_message_get(ssh_session session)
{
ssh_message msg = NULL;
int rc;
msg=ssh_message_pop_head(session);
if(msg) {
return msg;
}
if(session->ssh_message_list == NULL) {
session->ssh_message_list = ssh_list_new();
}
rc = ssh_handle_packets_termination(session, SSH_TIMEOUT_USER,
ssh_message_termination, session);
if(rc || session->session_state == SSH_SESSION_STATE_ERROR)
return NULL;
msg=ssh_list_pop_head(ssh_message, session->ssh_message_list);
msg = ssh_message_pop_head(session);
if (msg != NULL) {
return msg;
}
if (session->ssh_message_list == NULL) {
session->ssh_message_list = ssh_list_new();
if (session->ssh_message_list == NULL) {
ssh_set_error_oom(session);
return NULL;
}
}
rc = ssh_handle_packets_termination(session, SSH_TIMEOUT_USER,
ssh_message_termination, session);
if (rc || session->session_state == SSH_SESSION_STATE_ERROR) {
return NULL;
}
msg = ssh_list_pop_head(ssh_message, session->ssh_message_list);
return msg;
return msg;
}
/**

Просмотреть файл

@ -1422,12 +1422,14 @@ void ssh_packet_register_socket_callback(ssh_session session, ssh_socket s){
* @brief sets the callbacks for the packet layer
*/
void ssh_packet_set_callbacks(ssh_session session, ssh_packet_callbacks callbacks){
if(session->packet_callbacks == NULL){
session->packet_callbacks = ssh_list_new();
}
if (session->packet_callbacks != NULL) {
if (session->packet_callbacks == NULL) {
session->packet_callbacks = ssh_list_new();
if (session->packet_callbacks == NULL) {
ssh_set_error_oom(session);
return;
}
}
ssh_list_append(session->packet_callbacks, callbacks);
}
}
/** @internal

Просмотреть файл

@ -138,6 +138,9 @@ static void torture_callbacks_execute_list(void **state){
};
(void)state;
assert_non_null(list);
ssh_callbacks_init(&c1);
ssh_callbacks_init(&c2);
ssh_callbacks_init(&c3);
@ -213,6 +216,8 @@ static void torture_callbacks_iterate(void **state){
(void)state; /* unused */
assert_non_null(list);
ssh_callbacks_init(&c1);
ssh_callbacks_init(&c2);