aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAleksandr Mezin <mezin.alexander@gmail.com>2022-02-09 06:26:18 +0600
committerSimon Ser <contact@emersion.fr>2022-03-25 09:43:53 +0000
commit79c84ed3f132fd6bc01c2f62a8477d8d1a462b67 (patch)
tree31208a04f192a5eeb429999734dbf603e92cb4af /src
parentutil: set errno in wl_map_insert_at() (diff)
downloadwayland-79c84ed3f132fd6bc01c2f62a8477d8d1a462b67.tar
wayland-79c84ed3f132fd6bc01c2f62a8477d8d1a462b67.tar.gz
wayland-79c84ed3f132fd6bc01c2f62a8477d8d1a462b67.tar.bz2
wayland-79c84ed3f132fd6bc01c2f62a8477d8d1a462b67.tar.lz
wayland-79c84ed3f132fd6bc01c2f62a8477d8d1a462b67.tar.xz
wayland-79c84ed3f132fd6bc01c2f62a8477d8d1a462b67.tar.zst
wayland-79c84ed3f132fd6bc01c2f62a8477d8d1a462b67.zip
client, server: handle wl_map_insert_new() failures
Signed-off-by: Aleksandr Mezin <mezin.alexander@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/wayland-client.c13
-rw-r--r--src/wayland-server.c9
2 files changed, 19 insertions, 3 deletions
diff --git a/src/wayland-client.c b/src/wayland-client.c
index a9fb01e..75692e6 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -430,6 +430,10 @@ proxy_create(struct wl_proxy *factory, const struct wl_interface *interface,
proxy->version = version;
proxy->object.id = wl_map_insert_new(&display->objects, 0, proxy);
+ if (proxy->object.id == 0) {
+ free(proxy);
+ return NULL;
+ }
return proxy;
}
@@ -1158,11 +1162,16 @@ wl_display_connect_to_fd(int fd)
pthread_cond_init(&display->reader_cond, NULL);
display->reader_count = 0;
- wl_map_insert_new(&display->objects, 0, NULL);
+ if (wl_map_insert_at(&display->objects, 0, 0, NULL) == -1)
+ goto err_connection;
- display->proxy.object.interface = &wl_display_interface;
display->proxy.object.id =
wl_map_insert_new(&display->objects, 0, display);
+
+ if (display->proxy.object.id == 0)
+ goto err_connection;
+
+ display->proxy.object.interface = &wl_display_interface;
display->proxy.display = display;
display->proxy.object.implementation = (void(**)(void)) &display_listener;
display->proxy.user_data = display;
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 9fc337b..a503452 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -1826,8 +1826,13 @@ wl_resource_create(struct wl_client *client,
if (resource == NULL)
return NULL;
- if (id == 0)
+ if (id == 0) {
id = wl_map_insert_new(&client->objects, 0, NULL);
+ if (id == 0) {
+ free(resource);
+ return NULL;
+ }
+ }
resource->object.id = id;
resource->object.interface = interface;
@@ -2240,6 +2245,8 @@ wl_client_add_resource(struct wl_client *client,
resource->object.id =
wl_map_insert_new(&client->objects,
WL_MAP_ENTRY_LEGACY, resource);
+ if (resource->object.id == 0)
+ return 0;
} else if (wl_map_insert_at(&client->objects, WL_MAP_ENTRY_LEGACY,
resource->object.id, resource) < 0) {
if (errno == EINVAL) {