Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: Uli Schlachter <psychon <at> znc.in>
Subject: [PATCH] Error out when creating a simplewindow with invalid geometries
Newsgroups: gmane.comp.window-managers.awesome.devel
Date: Tuesday 17th March 2009 15:56:58 UTC (over 8 years ago)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

There is an integer overflow in the simplewindow code. If you try to create
a
window with e.g. height = 50 and border_width = 30, this would create a X
window with real_height = height - 2 * border_width = (uint_16_t) -10.
This caused a BadAlloc error reply which is hard to trace down.

With this patch applied, simplewindow_init() now lowers the border_width of
the
new window to avoid this integer overflow and additionally prints a error
on
stderr. This is still not good, but at least it's better than a BadAlloc
error.

This was found via the following lua fragment:
 naughty.config.border_width = 50
 naughty.notify({ text = "test" })

Signed-off-by: Uli Schlachter 
- ---
 swindow.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/swindow.c b/swindow.c
index 487ad8e..423d174 100644
- --- a/swindow.c
+++ b/swindow.c
@@ -83,6 +83,20 @@ simplewindow_init(simple_window_t *sw,
     const uint32_t gc_mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND;
     const uint32_t gc_values[2] = { s->black_pixel, s->white_pixel };

+    if (MIN(geometry.width, geometry.height) <= 2 * border_width)
+    {
+        /* The border_width is so big that there would be no space left in
the
+         * window. This now adjusts border_width so that there is at least
1px
+         * space inside the window, except when we were already called
with a
+         * width/height of 0, in which case this will likely lead to a X
+         * protocol error.
+         */
+        border_width = MIN(geometry.width, geometry.height) / 2;
+        if (border_width > 0)
+            border_width--;
+        fprintf(stderr, "error: Attempted to create a window with too
large
border_width / too small size\n");
+    }
+
     sw->geometry.x = geometry.x;
     sw->geometry.y = geometry.y;
     sw->geometry.width = geometry.width;
- --
1.6.2

- --
"Do you know that books smell like nutmeg or some spice from a foreign
land?"
                                                  -- Faber in Fahrenheit
451
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkm/yEgACgkQABixOSrV998jAQCg1Un3JbyQPOLTiEazEJIltN4d
IjUAnAknOWz+/eaibHaCObWTqGgNfrof
=uiIu
-----END PGP SIGNATURE-----

-- 
To unsubscribe, send mail to [email protected]
 
CD: 2ms