Skip to content

Commit

Permalink
Complete auth only when all bus replies have been received
Browse files Browse the repository at this point in the history
This is a fixup for the previous commit.

Signed-off-by: Alberto Mardegan <a.mardegan@omp.ru>
  • Loading branch information
mardy committed May 8, 2024
1 parent e8f1e87 commit 0e63504
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions flatpak-proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ struct FlatpakProxyClient
AuthState auth_state;
/* Only set if auth_state == AUTH_WAITING_FOR_BACKLOG */
gsize auth_server_backlog;
gsize auth_server_replies;
GByteArray *auth_buffer;

ProxySide client_side;
Expand Down Expand Up @@ -2610,6 +2611,20 @@ got_buffer_from_client (FlatpakProxyClient *client, ProxySide *side, Buffer *buf
queue_initial_name_ops (client);
}

static void
check_pending_auth_lines (FlatpakProxyClient *client)
{
if (client->auth_server_replies == client->auth_server_backlog)
{
client->auth_state = AUTH_COMPLETE;
}
else if (client->auth_server_replies > client->auth_server_backlog)
{
/* This should really never happen */
g_warning ("Received more auth replies than lines sent");
}
}

static void
got_buffer_from_bus (FlatpakProxyClient *client, ProxySide *side, Buffer *buffer)
{
Expand Down Expand Up @@ -2901,7 +2916,8 @@ find_auth_end (FlatpakProxyClient *client, Buffer *buffer)
}
else
{
/* No end-of-line in this buffer */
/* No more end-of-line in this buffer */
client->auth_server_backlog = lines_skipped;
g_byte_array_remove_range (client->auth_buffer, 0, offset);

/* Abort if more than 16k before newline, similar to what dbus-daemon does */
Expand Down Expand Up @@ -2982,9 +2998,10 @@ side_in_cb (GSocket *socket, GIOCondition condition, gpointer user_data)
got_buffer_from_side (side, buffer);

if (found_auth_end)
client->auth_state = client->auth_server_backlog
? AUTH_WAITING_FOR_BACKLOG
: AUTH_COMPLETE;
{
client->auth_state = AUTH_WAITING_FOR_BACKLOG;
check_pending_auth_lines (client);
}
}
else
{
Expand All @@ -3005,7 +3022,8 @@ side_in_cb (GSocket *socket, GIOCondition condition, gpointer user_data)
{
line_start = line_end + strlen (AUTH_LINE_SENTINEL);

if (--client->auth_server_backlog == 0)
client->auth_server_replies++;
if (client->auth_server_replies == client->auth_server_backlog)
{
buffer->size = line_start - buffer->data;
extra_data = buffer->pos - buffer->size;
Expand All @@ -3022,8 +3040,7 @@ side_in_cb (GSocket *socket, GIOCondition condition, gpointer user_data)

got_buffer_from_side (side, buffer);

if (client->auth_server_backlog == 0)
client->auth_state = AUTH_COMPLETE;
check_pending_auth_lines (client);
}
else
{
Expand Down

0 comments on commit 0e63504

Please sign in to comment.