[PATCH 2/2 (v2 for previous damage patch)] wlsc_compositor: check damage rectangles

juan.j.zhao at intel.com juan.j.zhao at intel.com
Mon Oct 31 00:17:59 PDT 2011


From: Juan Zhao <juan.j.zhao at intel.com>

avoid the wrong rectangles error sent by the clients.
---
 compositor/compositor.c |    9 +++++++++
 compositor/compositor.h |    3 +++
 2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/compositor/compositor.c b/compositor/compositor.c
index 53b282a..2533e86 100644
--- a/compositor/compositor.c
+++ b/compositor/compositor.c
@@ -292,6 +292,15 @@ wlsc_surface_damage_rectangle(struct wlsc_surface *surface,
 			      int32_t width, int32_t height)
 {
 	struct wlsc_compositor *compositor = surface->compositor;
+	/*The Width and Height can be generated by client, and may be incorrect.
+	  add boundary check before calling pixman api, 
+	  which may cause server segment fault*/
+	if( x < 0 || y < 0 || 
+	    width > OUTPUT_MAX_WIDTH || height > OUTPUT_MAX_HEIGHT) {
+		if(wl_debug)
+			fprintf(stderr, "damagate rectangle error!\n");
+		return;
+	}
 
 	pixman_region32_union_rect(&surface->damage,
 				   &surface->damage,
diff --git a/compositor/compositor.h b/compositor/compositor.h
index 421b80e..234c102 100644
--- a/compositor/compositor.h
+++ b/compositor/compositor.h
@@ -236,6 +236,9 @@ struct wlsc_compositor {
 #define MODIFIER_CTRL	(1 << 8)
 #define MODIFIER_ALT	(1 << 9)
 #define MODIFIER_SUPER	(1 << 10)
+#define OUTPUT_MAX_WIDTH (1 << 16)
+#define OUTPUT_MAX_HEIGHT (1 << 16)
+
 
 enum wlsc_output_flags {
 	WL_OUTPUT_FLIPPED = 0x01
-- 
1.7.1



More information about the wayland-devel mailing list