]> git.sur5r.net Git - i3/i3/commitdiff
libi3: Add basic validation to hex color conversion 2838/head
authorTony Crisci <tony@dubstepdish.com>
Wed, 12 Jul 2017 21:50:19 +0000 (17:50 -0400)
committerTony Crisci <tony@dubstepdish.com>
Wed, 12 Jul 2017 21:53:15 +0000 (17:53 -0400)
Make sure a given hex color is the expected length and begins with a hash in
draw_util_hex_to_color() to avoid memory errors.

fixes #2829

libi3/draw_util.c

index e4f0d065abcb9b010cbb49fe60af73ca4b48ae96..6a2e93dcd8e3a413099e2e34b119fcfbf13faf93 100644 (file)
@@ -84,6 +84,11 @@ void draw_util_surface_set_size(surface_t *surface, int width, int height) {
  *
  */
 color_t draw_util_hex_to_color(const char *color) {
+    if (strlen(color) < 6 || color[0] != '#') {
+        ELOG("Could not parse color: %s\n", color);
+        return draw_util_hex_to_color("#A9A9A9");
+    }
+
     char alpha[2];
     if (strlen(color) == strlen("#rrggbbaa")) {
         alpha[0] = color[7];