plymouth/SOURCES/0006-boot-server-free-the-a...

352 lines
16 KiB
Diff

From ebb1c642cd62592afc1ece9e0cf5d2ec9dfb84c0 Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Mon, 15 Oct 2018 21:56:03 -0400
Subject: [PATCH 6/6] boot-server: free the argument and triggers
coverity found some pervasive leaking of the argument
and triggers.
This commit mops them up.
---
src/ply-boot-server.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/src/ply-boot-server.c b/src/ply-boot-server.c
index 3c1a268..ff0e6fd 100644
--- a/src/ply-boot-server.c
+++ b/src/ply-boot-server.c
@@ -359,60 +359,61 @@ print_connection_process_identity (ply_boot_connection_t *connection)
static void
ply_boot_connection_on_request (ply_boot_connection_t *connection)
{
ply_boot_server_t *server;
char *command, *argument;
assert (connection != NULL);
assert (connection->fd >= 0);
server = connection->server;
assert (server != NULL);
if (!ply_boot_connection_read_request (connection,
&command, &argument)) {
ply_trace ("could not read connection request");
return;
}
if (ply_is_tracing ())
print_connection_process_identity (connection);
if (!ply_boot_connection_is_from_root (connection)) {
ply_error ("request came from non-root user");
if (!ply_write (connection->fd,
PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NAK,
strlen (PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NAK)))
ply_trace ("could not finish writing is-not-root nak: %m");
+ free (argument);
free (command);
return;
}
if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_UPDATE) == 0) {
if (!ply_write (connection->fd,
PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ACK,
strlen (PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ACK)) &&
errno != EPIPE)
ply_trace ("could not finish writing update reply: %m");
ply_trace ("got update request");
if (server->update_handler != NULL)
server->update_handler (server->user_data, argument, server);
free (argument);
free (command);
return;
} else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_CHANGE_MODE) == 0) {
if (!ply_write (connection->fd,
PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ACK,
strlen (PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ACK)))
ply_trace ("could not finish writing update reply: %m");
ply_trace ("got change mode notification");
if (server->change_mode_handler != NULL)
server->change_mode_handler (server->user_data, argument, server);
free (argument);
free (command);
return;
} else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_SYSTEM_UPDATE) == 0) {
@@ -439,105 +440,112 @@ ply_boot_connection_on_request (ply_boot_connection_t *connection)
} else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_SYSTEM_INITIALIZED) == 0) {
ply_trace ("got system initialized notification");
if (server->system_initialized_handler != NULL)
server->system_initialized_handler (server->user_data, server);
} else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_ERROR) == 0) {
ply_trace ("got error notification");
if (server->error_handler != NULL)
server->error_handler (server->user_data, server);
} else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_SHOW_SPLASH) == 0) {
ply_trace ("got show splash request");
if (server->show_splash_handler != NULL)
server->show_splash_handler (server->user_data, server);
} else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_HIDE_SPLASH) == 0) {
ply_trace ("got hide splash request");
if (server->hide_splash_handler != NULL)
server->hide_splash_handler (server->user_data, server);
} else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_DEACTIVATE) == 0) {
ply_trigger_t *deactivate_trigger;
ply_trace ("got deactivate request");
deactivate_trigger = ply_trigger_new (NULL);
ply_trigger_add_handler (deactivate_trigger,
(ply_trigger_handler_t)
ply_boot_connection_on_deactivated,
connection);
if (server->deactivate_handler != NULL)
server->deactivate_handler (server->user_data, deactivate_trigger, server);
+ else
+ ply_trigger_free (deactivate_trigger);
free (argument);
free (command);
return;
} else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_REACTIVATE) == 0) {
ply_trace ("got reactivate request");
if (server->reactivate_handler != NULL)
server->reactivate_handler (server->user_data, server);
} else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_QUIT) == 0) {
bool retain_splash;
ply_trigger_t *quit_trigger;
retain_splash = (bool) argument[0];
ply_trace ("got quit %srequest", retain_splash ? "--retain-splash " : "");
quit_trigger = ply_trigger_new (NULL);
ply_trigger_add_handler (quit_trigger,
(ply_trigger_handler_t)
ply_boot_connection_on_quit_complete,
connection);
if (server->quit_handler != NULL)
server->quit_handler (server->user_data, retain_splash, quit_trigger, server);
+ else
+ ply_trigger_free (quit_trigger);
free (argument);
free (command);
return;
} else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_PASSWORD) == 0) {
ply_trigger_t *answer;
ply_trace ("got password request");
answer = ply_trigger_new (NULL);
ply_trigger_add_handler (answer,
(ply_trigger_handler_t)
ply_boot_connection_on_password_answer,
connection);
if (server->ask_for_password_handler != NULL) {
server->ask_for_password_handler (server->user_data,
argument,
answer,
server);
+ } else {
+ ply_trigger_free (answer);
+ free (argument);
}
/* will reply later
*/
free (command);
return;
} else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_CACHED_PASSWORD) == 0) {
ply_list_node_t *node;
ply_buffer_t *buffer;
size_t buffer_size;
uint32_t size;
ply_trace ("got cached password request");
buffer = ply_buffer_new ();
node = ply_list_get_first_node (server->cached_passwords);
ply_trace ("There are %d cached passwords",
ply_list_get_length (server->cached_passwords));
/* Add each answer separated by their NUL terminators into
* a buffer that we write out to the client
*/
while (node != NULL) {
ply_list_node_t *next_node;
const char *password;
next_node = ply_list_get_next_node (server->cached_passwords, node);
password = (const char *) ply_list_node_get_data (node);
@@ -565,146 +573,155 @@ ply_boot_connection_on_request (ply_boot_connection_t *connection)
ply_list_get_length (server->cached_passwords));
if (!ply_write (connection->fd,
PLY_BOOT_PROTOCOL_RESPONSE_TYPE_MULTIPLE_ANSWERS,
strlen (PLY_BOOT_PROTOCOL_RESPONSE_TYPE_MULTIPLE_ANSWERS)) ||
!ply_write_uint32 (connection->fd,
size) ||
!ply_write (connection->fd,
ply_buffer_get_bytes (buffer), size))
ply_trace ("could not finish writing cached answer reply: %m");
}
ply_buffer_free (buffer);
free (command);
return;
} else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_QUESTION) == 0) {
ply_trigger_t *answer;
ply_trace ("got question request");
answer = ply_trigger_new (NULL);
ply_trigger_add_handler (answer,
(ply_trigger_handler_t)
ply_boot_connection_on_question_answer,
connection);
if (server->ask_question_handler != NULL) {
server->ask_question_handler (server->user_data,
argument,
answer,
server);
+ } else {
+ ply_trigger_free (answer);
+ free (argument);
}
/* will reply later
*/
free (command);
return;
} else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_SHOW_MESSAGE) == 0) {
ply_trace ("got show message request");
if (server->display_message_handler != NULL)
server->display_message_handler (server->user_data, argument, server);
} else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_HIDE_MESSAGE) == 0) {
ply_trace ("got hide message request");
if (server->hide_message_handler != NULL)
server->hide_message_handler (server->user_data, argument, server);
} else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_KEYSTROKE) == 0) {
ply_trigger_t *answer;
ply_trace ("got keystroke request");
answer = ply_trigger_new (NULL);
ply_trigger_add_handler (answer,
(ply_trigger_handler_t)
ply_boot_connection_on_keystroke_answer,
connection);
if (server->watch_for_keystroke_handler != NULL) {
server->watch_for_keystroke_handler (server->user_data,
argument,
answer,
server);
+ } else {
+ ply_trigger_free (answer);
+ free (argument);
}
/* will reply later
*/
free (command);
return;
} else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_KEYSTROKE_REMOVE) == 0) {
ply_trace ("got keystroke remove request");
if (server->ignore_keystroke_handler != NULL)
server->ignore_keystroke_handler (server->user_data,
argument,
server);
} else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_PROGRESS_PAUSE) == 0) {
ply_trace ("got progress pause request");
if (server->progress_pause_handler != NULL)
server->progress_pause_handler (server->user_data,
server);
} else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_PROGRESS_UNPAUSE) == 0) {
ply_trace ("got progress unpause request");
if (server->progress_unpause_handler != NULL)
server->progress_unpause_handler (server->user_data,
server);
} else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_NEWROOT) == 0) {
ply_trace ("got newroot request");
if (server->newroot_handler != NULL)
server->newroot_handler (server->user_data, argument, server);
} else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_HAS_ACTIVE_VT) == 0) {
bool answer = false;
ply_trace ("got has_active vt? request");
if (server->has_active_vt_handler != NULL)
answer = server->has_active_vt_handler (server->user_data, server);
if (!answer) {
if (!ply_write (connection->fd,
PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NAK,
strlen (PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NAK)))
ply_trace ("could not finish writing nak: %m");
+ free (argument);
free (command);
return;
}
} else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_PING) != 0) {
ply_error ("received unknown command '%s' from client", command);
if (!ply_write (connection->fd,
PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NAK,
strlen (PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NAK)))
ply_trace ("could not finish writing ping reply: %m");
+ free (argument);
free (command);
return;
}
if (!ply_write (connection->fd,
PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ACK,
strlen (PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ACK)))
ply_trace ("could not finish writing ack: %m");
+ free (argument);
free (command);
}
static void
ply_boot_connection_on_hangup (ply_boot_connection_t *connection)
{
ply_list_node_t *node;
ply_boot_server_t *server;
assert (connection != NULL);
assert (connection->server != NULL);
server = connection->server;
node = ply_list_find_node (server->connections, connection);
assert (node != NULL);
ply_boot_connection_free (connection);
ply_list_remove_node (server->connections, node);
}
static void
ply_boot_server_on_new_connection (ply_boot_server_t *server)
{
ply_boot_connection_t *connection;
int fd;
assert (server != NULL);
--
2.17.1