forked from external/yambar
module/sway-xkb: don’t add the “same” device multiple times
Not sure if Sway bug or not, but we’ve seen Sway presenting multiple input devices with the exact same ID (and nothing else differentiating them). This caused a crash in the sway-xkb module, since we didn’t check if we were already tracking the device, and thus bumped the “num_existing_inputs” variable multiple times for the same input object. This lead to a content() returning an array with uninitialized elements, and thus a crash. Closes #229
This commit is contained in:
parent
6ed576c719
commit
028011a816
2 changed files with 12 additions and 1 deletions
|
@ -67,6 +67,7 @@ content(struct module *mod)
|
|||
|
||||
mtx_lock(&mod->lock);
|
||||
|
||||
assert(m->num_existing_inputs <= m->num_inputs);
|
||||
struct exposable *particles[max(m->num_existing_inputs, 1)];
|
||||
|
||||
for (size_t i = 0, j = 0; i < m->num_inputs; i++) {
|
||||
|
@ -120,9 +121,12 @@ handle_input_reply(int type, const struct json_object *json, void *_mod)
|
|||
struct input *input = NULL;
|
||||
for (size_t i = 0; i < m->num_inputs; i++) {
|
||||
struct input *maybe_input = &m->inputs[i];
|
||||
if (strcmp(maybe_input->identifier, id) == 0) {
|
||||
if (strcmp(maybe_input->identifier, id) == 0 && !maybe_input->exists)
|
||||
{
|
||||
input = maybe_input;
|
||||
|
||||
LOG_DBG("adding: %s", id);
|
||||
|
||||
mtx_lock(&mod->lock);
|
||||
input->exists = true;
|
||||
m->num_existing_inputs++;
|
||||
|
@ -209,6 +213,8 @@ handle_input_event(int type, const struct json_object *json, void *_mod)
|
|||
|
||||
if (is_removed) {
|
||||
if (input->exists) {
|
||||
LOG_DBG("removing: %s", id);
|
||||
|
||||
mtx_lock(&mod->lock);
|
||||
input->exists = false;
|
||||
m->num_existing_inputs--;
|
||||
|
@ -220,6 +226,8 @@ handle_input_event(int type, const struct json_object *json, void *_mod)
|
|||
|
||||
if (is_added) {
|
||||
if (!input->exists) {
|
||||
LOG_DBG("adding: %s", id);
|
||||
|
||||
mtx_lock(&mod->lock);
|
||||
input->exists = true;
|
||||
m->num_existing_inputs++;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue