From 1bcf116859fd2a0f04c18bdc8ff9c2038f5f0e40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 30 Sep 2021 09:52:25 +0200 Subject: [PATCH] modules: handle udev_monitor_receive_device() returning NULL Closes #109 --- CHANGELOG.md | 3 +++ modules/backlight.c | 6 ++++-- modules/battery.c | 4 +++- modules/removables.c | 3 +++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f06a69..938c91e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,9 @@ * `left-margin` and `right-margin` from being rejected as invalid options. +* Crash when `udev_monitor_receive_device()` returned `NULL`. This + affected the “backlight”, “battery” and “removables” modules + (https://codeberg.org/dnkl/yambar/issues/109). ### Security diff --git a/modules/backlight.c b/modules/backlight.c index e7bca2e..292b067 100644 --- a/modules/backlight.c +++ b/modules/backlight.c @@ -189,9 +189,11 @@ run(struct module *mod) break; struct udev_device *dev = udev_monitor_receive_device(mon); - const char *sysname = udev_device_get_sysname(dev); + if (dev == NULL) + continue; - bool is_us = strcmp(sysname, m->device) == 0; + const char *sysname = udev_device_get_sysname(dev); + bool is_us = sysname != NULL && strcmp(sysname, m->device) == 0; udev_device_unref(dev); if (!is_us) diff --git a/modules/battery.c b/modules/battery.c index 215fa32..4f17de4 100644 --- a/modules/battery.c +++ b/modules/battery.c @@ -437,8 +437,10 @@ run(struct module *mod) if (fds[1].revents & POLLIN) { struct udev_device *dev = udev_monitor_receive_device(mon); - const char *sysname = udev_device_get_sysname(dev); + if (dev == NULL) + continue; + const char *sysname = udev_device_get_sysname(dev); bool is_us = sysname != NULL && strcmp(sysname, m->battery) == 0; udev_device_unref(dev); diff --git a/modules/removables.c b/modules/removables.c index a676ceb..04d2695 100644 --- a/modules/removables.c +++ b/modules/removables.c @@ -571,6 +571,9 @@ run(struct module *mod) if (fds[1].revents & POLLIN) { struct udev_device *dev = udev_monitor_receive_device(dev_mon); + if (dev == NULL) + continue; + if (handle_udev_event(mod, dev)) update = true; udev_device_unref(dev);