Skip to content

Commit

Permalink
bus/driver: send correct fd-count with credentials
Browse files Browse the repository at this point in the history
Fix the GetConnectionCredentials() API to send the correct number of FDs
with a message. We have to predict the number of FDs since we write
message headers before their body. This should be fine to predict,
though.

Signed-off-by: David Rheinsberg <david@readahead.eu>
  • Loading branch information
dvdhrm committed Oct 17, 2023
1 parent 2220a84 commit a1d5f94
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/bus/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,7 @@ static int driver_method_get_connection_credentials(Peer *peer, const char *path
DriverCredentials cred = DRIVER_CREDENTIALS_NULL;
Peer *connection = NULL;
const char *name;
size_t n_fds = 0;
size_t n_fds = 0, n_fds_expected;
int r;

c_dvar_read(in_v, "(s)", &name);
Expand All @@ -1453,14 +1453,15 @@ static int driver_method_get_connection_credentials(Peer *peer, const char *path
return DRIVER_E_PEER_NOT_FOUND;
}

driver_write_reply_header(out_v, peer, serial, driver_type_out_apsv, n_fds);
driver_fetch_credentials(peer->bus, connection, &cred);
n_fds_expected = (cred.pid_fd >= 0) ? 1 : 0;
driver_write_reply_header(out_v, peer, serial, driver_type_out_apsv, n_fds_expected);

c_dvar_write(out_v, "(");
driver_fetch_credentials(peer->bus, connection, &cred);
driver_append_credentials(out_v, &cred, &n_fds);
c_dvar_write(out_v, ")");

c_assert(n_fds == 0 || n_fds == 1);
c_assert(n_fds == n_fds_expected);

if (n_fds == 1)
r = driver_send_reply_with_fds(peer, out_v, serial, &cred.pid_fd, n_fds);
Expand Down

0 comments on commit a1d5f94

Please sign in to comment.