mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-24 21:05:40 +02:00
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
|
@ -115,6 +115,8 @@
|
|||
* network: missing SSID (recent kernels, or possibly wireless drivers,
|
||||
no longer provide the SSID in the `NL80211_CMD_NEW_STATION`
|
||||
response) ([#226][226]).
|
||||
* sway-xkb: crash when compositor presents multiple inputs with
|
||||
identical IDs ([#229][229]).
|
||||
|
||||
[169]: https://codeberg.org/dnkl/yambar/issues/169
|
||||
[172]: https://codeberg.org/dnkl/yambar/issues/172
|
||||
|
@ -123,6 +125,7 @@
|
|||
[198]: https://codeberg.org/dnkl/yambar/issues/198
|
||||
[221]: https://codeberg.org/dnkl/yambar/issues/221
|
||||
[226]: https://codeberg.org/dnkl/yambar/issues/226
|
||||
[229]: https://codeberg.org/dnkl/yambar/issues/229
|
||||
|
||||
|
||||
### Security
|
||||
|
|
|
@ -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
Reference in a new issue