ipc: Fix session deactivation negative array index access

It is possible for s->global_state.active_client_index to be -1 when
update_server_state_locked is called:

ipc_server_activate_session is only called from
ipc_handle_compositor_predict_frame, which is only called from
ipc_compositor_wait_frame.

So it is possible to deactivate a session that was never activated.
This commit is contained in:
Christoph Haag 2023-10-19 00:22:05 +02:00
parent 2c48daff5d
commit ef47498137

View file

@ -687,13 +687,14 @@ update_server_state_locked(struct ipc_server *s)
}
}
// if our currently-set active primary application is not
// if there is a currently-set active primary application and it is not
// actually active/displayable, use the fallback application
// instead.
volatile struct ipc_client_state *ics = &s->threads[s->global_state.active_client_index].ics;
if (!(ics->client_state.session_overlay == false && s->global_state.active_client_index >= 0 &&
ics->client_state.session_active)) {
s->global_state.active_client_index = fallback_active_application;
if (s->global_state.active_client_index >= 0) {
volatile struct ipc_client_state *ics = &s->threads[s->global_state.active_client_index].ics;
if (!(ics->client_state.session_overlay == false && ics->client_state.session_active)) {
s->global_state.active_client_index = fallback_active_application;
}
}