summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2022-06-28 11:59:26 +0200
committerSimon Ser <contact@emersion.fr>2022-06-28 11:59:26 +0200
commitc7fc1e79ca50402acdd8627dcdf7dd0286924d99 (patch)
tree3b21c089cf0b42a4540e01f8a33663f6ba1a2733
parent8e322a5a99db1cefb7494f082a5525d2cba64174 (diff)
downloadwayland-c7fc1e79ca50402acdd8627dcdf7dd0286924d99.tar.gz
util: set errno when hitting WL_MAP_MAX_OBJECTS
Callers may check errno when wl_map_insert_* functions return an error (since [1]). Make sure it's always set to a meaningful value when returning an error, otherwise callers might end up checking an errno coming from a completely different function. [1]: https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/205 Signed-off-by: Simon Ser <contact@emersion.fr> Fixes: b19488c7154b ("util: Limit size of wl_map")
-rw-r--r--src/wayland-util.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/wayland-util.c b/src/wayland-util.c
index 41f0986..bb2a183 100644
--- a/src/wayland-util.c
+++ b/src/wayland-util.c
@@ -232,6 +232,7 @@ wl_map_insert_new(struct wl_map *map, uint32_t flags, void *data)
* better make it a NULL so wl_map_for_each doesn't
* dereference it later. */
entry->data = NULL;
+ errno = ENOSPC;
return 0;
}
entry->data = data;
@@ -254,8 +255,10 @@ wl_map_insert_at(struct wl_map *map, uint32_t flags, uint32_t i, void *data)
i -= WL_SERVER_ID_START;
}
- if (i > WL_MAP_MAX_OBJECTS)
+ if (i > WL_MAP_MAX_OBJECTS) {
+ errno = ENOSPC;
return -1;
+ }
count = entries->size / sizeof *start;
if (count < i) {
@@ -299,8 +302,10 @@ wl_map_reserve_new(struct wl_map *map, uint32_t i)
i -= WL_SERVER_ID_START;
}
- if (i > WL_MAP_MAX_OBJECTS)
+ if (i > WL_MAP_MAX_OBJECTS) {
+ errno = ENOSPC;
return -1;
+ }
count = entries->size / sizeof *start;
if (count < i) {