commit 98b8e8f

Michael Forney  ·  2020-01-04 22:37:52 +0000 UTC
parent 8fdf857
Add missing error checks for resource creation
11 files changed,  +74, -22
+4, -0
 1@@ -793,6 +793,10 @@ bind_compositor(struct wl_client *client, void *data, uint32_t version, uint32_t
 2 	struct wl_resource *resource;
 3 
 4 	resource = wl_resource_create(client, &wl_compositor_interface, version, id);
 5+	if (!resource) {
 6+		wl_client_post_no_memory(client);
 7+		return;
 8+	}
 9 	wl_resource_set_implementation(resource, &compositor_impl, NULL, NULL);
10 }
11 
+5, -1
 1@@ -1,6 +1,6 @@
 2 /* swc: drm.c
 3  *
 4- * Copyright (c) 2013-2019 Michael Forney
 5+ * Copyright (c) 2013-2020 Michael Forney
 6  *
 7  * Permission is hereby granted, free of charge, to any person obtaining a copy
 8  * of this software and associated documentation files (the "Software"), to deal
 9@@ -240,6 +240,10 @@ bind_drm(struct wl_client *client, void *data, uint32_t version, uint32_t id)
10 	struct wl_resource *resource;
11 
12 	resource = wl_resource_create(client, &wl_drm_interface, version, id);
13+	if (!resource) {
14+		wl_client_post_no_memory(client);
15+		return;
16+	}
17 	wl_resource_set_implementation(resource, &drm_impl, NULL, NULL);
18 
19 	if (version >= 2)
+3, -1
 1@@ -1,6 +1,6 @@
 2 /* swc: libswc/keyboard.c
 3  *
 4- * Copyright (c) 2013 Michael Forney
 5+ * Copyright (c) 2013-2020 Michael Forney
 6  *
 7  * Based in part upon input.c from weston, which is:
 8  *
 9@@ -310,6 +310,8 @@ keyboard_bind(struct keyboard *keyboard, struct wl_client *client, uint32_t vers
10 	struct wl_resource *client_resource;
11 
12 	client_resource = wl_resource_create(client, &wl_keyboard_interface, version, id);
13+	if (!client_resource)
14+		return NULL;
15 	wl_resource_set_implementation(client_resource, &keyboard_impl, keyboard, &unbind);
16 
17 	/* Subtract one to remove terminating NULL character. */
+5, -1
 1@@ -1,6 +1,6 @@
 2 /* swc: libswc/panel_manager.c
 3  *
 4- * Copyright (c) 2013-2019 Michael Forney
 5+ * Copyright (c) 2013-2020 Michael Forney
 6  *
 7  * Permission is hereby granted, free of charge, to any person obtaining a copy
 8  * of this software and associated documentation files (the "Software"), to deal
 9@@ -47,6 +47,10 @@ bind_panel_manager(struct wl_client *client, void *data, uint32_t version, uint3
10 	struct wl_resource *resource;
11 
12 	resource = wl_resource_create(client, &swc_panel_manager_interface, version, id);
13+	if (!resource) {
14+		wl_client_post_no_memory(client);
15+		return;
16+	}
17 	wl_resource_set_implementation(resource, &panel_manager_impl, NULL, NULL);
18 }
19 
+3, -1
 1@@ -1,6 +1,6 @@
 2 /* swc: libswc/pointer.c
 3  *
 4- * Copyright (c) 2013, 2014 Michael Forney
 5+ * Copyright (c) 2013-2020 Michael Forney
 6  *
 7  * Permission is hereby granted, free of charge, to any person obtaining a copy
 8  * of this software and associated documentation files (the "Software"), to deal
 9@@ -349,6 +349,8 @@ pointer_bind(struct pointer *pointer, struct wl_client *client, uint32_t version
10 	struct wl_resource *client_resource;
11 
12 	client_resource = wl_resource_create(client, &wl_pointer_interface, version, id);
13+	if (!client_resource)
14+		return NULL;
15 	wl_resource_set_implementation(client_resource, &pointer_impl, pointer, &unbind);
16 	input_focus_add_resource(&pointer->focus, client_resource);
17 
+10, -3
 1@@ -42,13 +42,20 @@ region_new(struct wl_client *client, uint32_t version, uint32_t id)
 2 	struct region *region;
 3 
 4 	region = malloc(sizeof(*region));
 5-
 6 	if (!region)
 7-		return NULL;
 8+		goto error0;
 9 
10-	pixman_region32_init(&region->region);
11 	region->resource = wl_resource_create(client, &wl_region_interface, version, id);
12+	if (!region->resource)
13+		goto error1;
14+
15+	pixman_region32_init(&region->region);
16 	wl_resource_set_implementation(region->resource, &region_impl, region, &region_destroy);
17 
18 	return region;
19+
20+error1:
21+	free(region);
22+error0:
23+	return NULL;
24 }
+9, -3
 1@@ -1,6 +1,6 @@
 2 /* swc: libswc/seat.c
 3  *
 4- * Copyright (c) 2013, 2014 Michael Forney
 5+ * Copyright (c) 2013-2020 Michael Forney
 6  *
 7  * Permission is hereby granted, free of charge, to any person obtaining a copy
 8  * of this software and associated documentation files (the "Software"), to deal
 9@@ -124,7 +124,8 @@ get_pointer(struct wl_client *client, struct wl_resource *resource, uint32_t id)
10 {
11 	struct seat *seat = wl_resource_get_user_data(resource);
12 
13-	pointer_bind(&seat->pointer, client, wl_resource_get_version(resource), id);
14+	if (!pointer_bind(&seat->pointer, client, wl_resource_get_version(resource), id))
15+		wl_resource_post_no_memory(resource);
16 }
17 
18 static void
19@@ -132,7 +133,8 @@ get_keyboard(struct wl_client *client, struct wl_resource *resource, uint32_t id
20 {
21 	struct seat *seat = wl_resource_get_user_data(resource);
22 
23-	keyboard_bind(seat->base.keyboard, client, wl_resource_get_version(resource), id);
24+	if (!keyboard_bind(seat->base.keyboard, client, wl_resource_get_version(resource), id))
25+		wl_resource_post_no_memory(resource);
26 }
27 
28 static void
29@@ -154,6 +156,10 @@ bind_seat(struct wl_client *client, void *data, uint32_t version, uint32_t id)
30 	struct wl_resource *resource;
31 
32 	resource = wl_resource_create(client, &wl_seat_interface, version, id);
33+	if (!resource) {
34+		wl_client_post_no_memory(client);
35+		return;
36+	}
37 	wl_resource_set_implementation(resource, &seat_impl, seat, &remove_resource);
38 	wl_list_insert(&seat->resources, wl_resource_get_link(resource));
39 
+5, -1
 1@@ -1,6 +1,6 @@
 2 /* swc: libswc/shell.c
 3  *
 4- * Copyright (c) 2013-2019 Michael Forney
 5+ * Copyright (c) 2013-2020 Michael Forney
 6  *
 7  * Permission is hereby granted, free of charge, to any person obtaining a copy
 8  * of this software and associated documentation files (the "Software"), to deal
 9@@ -49,6 +49,10 @@ bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
10 	struct wl_resource *resource;
11 
12 	resource = wl_resource_create(client, &wl_shell_interface, version, id);
13+	if (!resource) {
14+		wl_client_post_no_memory(client);
15+		return;
16+	}
17 	wl_resource_set_implementation(resource, &shell_implementation, NULL, NULL);
18 }
19 
+5, -1
 1@@ -1,6 +1,6 @@
 2 /* swc: libswc/shm.c
 3  *
 4- * Copyright (c) 2013-2019 Michael Forney
 5+ * Copyright (c) 2013-2020 Michael Forney
 6  *
 7  * Based in part upon wayland-shm.c from wayland, which is:
 8  *
 9@@ -200,6 +200,10 @@ bind_shm(struct wl_client *client, void *data, uint32_t version, uint32_t id)
10 	struct wl_resource *resource;
11 
12 	resource = wl_resource_create(client, &wl_shm_interface, version, id);
13+	if (!resource) {
14+		wl_client_post_no_memory(client);
15+		return;
16+	}
17 	wl_resource_set_implementation(resource, &shm_impl, shm, NULL);
18 
19 	wl_shm_send_format(resource, WL_SHM_FORMAT_XRGB8888);
+5, -1
 1@@ -1,6 +1,6 @@
 2 /* swc: libswc/subcompositor.c
 3  *
 4- * Copyright (c) 2015-2019 Michael Forney
 5+ * Copyright (c) 2015-2020 Michael Forney
 6  *
 7  * Permission is hereby granted, free of charge, to any person obtaining a copy
 8  * of this software and associated documentation files (the "Software"), to deal
 9@@ -54,6 +54,10 @@ bind_subcompositor(struct wl_client *client, void *data, uint32_t version, uint3
10 	struct wl_resource *resource;
11 
12 	resource = wl_resource_create(client, &wl_subcompositor_interface, version, id);
13+	if (!resource) {
14+		wl_client_post_no_memory(client);
15+		return;
16+	}
17 	wl_resource_set_implementation(resource, &subcompositor_impl, NULL, NULL);
18 }
19 
+20, -9
 1@@ -1,6 +1,6 @@
 2 /* swc: surface.c
 3  *
 4- * Copyright (c) 2013 Michael Forney
 5+ * Copyright (c) 2013-2020 Michael Forney
 6  *
 7  * Permission is hereby granted, free of charge, to any person obtaining a copy
 8  * of this software and associated documentation files (the "Software"), to deal
 9@@ -171,8 +171,12 @@ frame(struct wl_client *client, struct wl_resource *resource, uint32_t id)
10 	struct surface *surface = wl_resource_get_user_data(resource);
11 	struct wl_resource *callback_resource;
12 
13-	surface->pending.commit |= SURFACE_COMMIT_FRAME;
14 	callback_resource = wl_resource_create(client, &wl_callback_interface, 1, id);
15+	if (!callback_resource) {
16+		wl_resource_post_no_memory(resource);
17+		return;
18+	}
19+	surface->pending.commit |= SURFACE_COMMIT_FRAME;
20 	wl_resource_set_implementation(callback_resource, NULL, NULL, &remove_resource);
21 	wl_list_insert(surface->pending.state.frame_callbacks.prev, wl_resource_get_link(callback_resource));
22 }
23@@ -310,7 +314,7 @@ surface_destroy(struct wl_resource *resource)
24 /**
25  * Construct a new surface, adding it to the given client as id.
26  *
27- * The surface will be free'd automatically when it's resource is destroyed.
28+ * The surface will be free'd automatically when its resource is destroyed.
29  *
30  * @return The newly allocated surface.
31  */
32@@ -319,8 +323,14 @@ surface_new(struct wl_client *client, uint32_t version, uint32_t id)
33 {
34 	struct surface *surface;
35 
36-	if (!(surface = malloc(sizeof(*surface))))
37-		return NULL;
38+	surface = malloc(sizeof(*surface));
39+	if (!surface)
40+		goto error0;
41+
42+	surface->resource = wl_resource_create(client, &wl_surface_interface, version, id);
43+	if (!surface->resource)
44+		goto error1;
45+	wl_resource_set_implementation(surface->resource, &surface_impl, surface, &surface_destroy);
46 
47 	/* Initialize the surface. */
48 	surface->pending.commit = 0;
49@@ -330,11 +340,12 @@ surface_new(struct wl_client *client, uint32_t version, uint32_t id)
50 	state_initialize(&surface->state);
51 	state_initialize(&surface->pending.state);
52 
53-	/* Add the surface to the client. */
54-	surface->resource = wl_resource_create(client, &wl_surface_interface, version, id);
55-	wl_resource_set_implementation(surface->resource, &surface_impl, surface, &surface_destroy);
56-
57 	return surface;
58+
59+error1:
60+	free(surface);
61+error0:
62+	return NULL;
63 }
64 
65 void