summaryrefslogtreecommitdiff
path: root/bus
diff options
context:
space:
mode:
authorJan Tojnar <jtojnar@gmail.com>2022-04-20 11:07:25 +0200
committerJan Tojnar <jtojnar@gmail.com>2022-04-20 11:24:40 +0200
commitb551b3e9737958216a1a9d359150a4110a9d0549 (patch)
tree53b12c9a8599b90ad313490280e909e180dc5b0a /bus
parent14b5119f9e345ca24760ffc36e026c9d27aea4c4 (diff)
downloaddbus-b551b3e9737958216a1a9d359150a4110a9d0549.tar.gz
bus/dir-watch: Do not crash with > 128 dirs
Without this running, dbus-daemon with long XDG_DATA_DIRS will crash on out-of-bounds write: $ XDG_DATA_DIRS=$(seq -f "/foo/%g" -s ':' 129) dbus-daemon --session *** stack smashing detected ***: terminated
Diffstat (limited to 'bus')
-rw-r--r--bus/dir-watch-inotify.c7
-rw-r--r--bus/dir-watch-kqueue.c7
2 files changed, 12 insertions, 2 deletions
diff --git a/bus/dir-watch-inotify.c b/bus/dir-watch-inotify.c
index b52a24c0..9beadb0e 100644
--- a/bus/dir-watch-inotify.c
+++ b/bus/dir-watch-inotify.c
@@ -108,12 +108,17 @@ _set_watched_dirs_internal (DBusList **directories)
i = 0;
link = _dbus_list_get_first_link (directories);
- while (link != NULL)
+ while (link != NULL && i < MAX_DIRS_TO_WATCH)
{
new_dirs[i++] = (char *)link->data;
link = _dbus_list_get_next_link (directories, link);
}
+ if (link != NULL)
+ {
+ _dbus_warn ("Too many directories to watch them all, only watching first %d.", MAX_DIRS_TO_WATCH);
+ }
+
/* Look for directories in both the old and new sets, if
* we find one, move its data into the new set.
*/
diff --git a/bus/dir-watch-kqueue.c b/bus/dir-watch-kqueue.c
index 183db241..15519fcb 100644
--- a/bus/dir-watch-kqueue.c
+++ b/bus/dir-watch-kqueue.c
@@ -218,12 +218,17 @@ bus_set_watched_dirs (BusContext *context, DBusList **directories)
i = 0;
link = _dbus_list_get_first_link (directories);
- while (link != NULL)
+ while (link != NULL && i < MAX_DIRS_TO_WATCH)
{
new_dirs[i++] = (char *)link->data;
link = _dbus_list_get_next_link (directories, link);
}
+ if (link != NULL)
+ {
+ _dbus_warn ("Too many directories to watch them all, only watching first %d.", MAX_DIRS_TO_WATCH);
+ }
+
/* Look for directories in both the old and new sets, if
* we find one, move its data into the new set.
*/