[vte/vte-0-44] api: Validate colour values



commit c1cef4190a70b01b251e08139c8028f0371111c2
Author: Christian Persch <chpe gnome org>
Date:   Mon May 16 10:26:16 2016 +0200

    api: Validate colour values
    
    Don't allow in a GdkRGBA whose components exceed the allowed range of 0..1.
    
    (cherry picked from commit cb7589ea01526ec696daae60c5ff8a96d00a73e4)

 src/vtegtk.cc |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)
---
diff --git a/src/vtegtk.cc b/src/vtegtk.cc
index a2591b4..98ff6e0 100644
--- a/src/vtegtk.cc
+++ b/src/vtegtk.cc
@@ -107,6 +107,15 @@ guint signals[LAST_SIGNAL];
 GParamSpec *pspecs[LAST_PROP];
 GTimer *process_timer;
 
+static bool
+valid_color(GdkRGBA const* color)
+{
+        return color->red >= 0. && color->red <= 1. &&
+               color->green >= 0. && color->green <= 1. &&
+               color->blue >= 0. && color->blue <= 1. &&
+               color->alpha >= 0. && color->alpha <= 1.;
+}
+
 VteTerminalPrivate *_vte_terminal_get_impl(VteTerminal *terminal)
 {
         return IMPL(terminal);
@@ -2691,6 +2700,7 @@ vte_terminal_set_color_background(VteTerminal *terminal,
 {
         g_return_if_fail(VTE_IS_TERMINAL(terminal));
         g_return_if_fail(background != NULL);
+        g_return_if_fail(valid_color(background));
 
         auto impl = IMPL(terminal);
         impl->set_color_background(vte::color::rgb(background));
@@ -2710,6 +2720,7 @@ vte_terminal_set_color_bold(VteTerminal *terminal,
                             const GdkRGBA *bold)
 {
         g_return_if_fail(VTE_IS_TERMINAL(terminal));
+        g_return_if_fail(bold == nullptr || valid_color(bold));
 
         auto impl = IMPL(terminal);
         if (bold)
@@ -2732,6 +2743,7 @@ vte_terminal_set_color_cursor(VteTerminal *terminal,
                               const GdkRGBA *cursor_background)
 {
         g_return_if_fail(VTE_IS_TERMINAL(terminal));
+        g_return_if_fail(cursor_background == nullptr || valid_color(cursor_background));
 
         auto impl = IMPL(terminal);
         if (cursor_background)
@@ -2756,6 +2768,7 @@ vte_terminal_set_color_cursor_foreground(VteTerminal *terminal,
                                          const GdkRGBA *cursor_foreground)
 {
         g_return_if_fail(VTE_IS_TERMINAL(terminal));
+        g_return_if_fail(cursor_foreground == nullptr || valid_color(cursor_foreground));
 
         auto impl = IMPL(terminal);
         if (cursor_foreground)
@@ -2776,7 +2789,9 @@ vte_terminal_set_color_foreground(VteTerminal *terminal,
                                   const GdkRGBA *foreground)
 {
         g_return_if_fail(VTE_IS_TERMINAL(terminal));
-        g_return_if_fail(foreground != NULL);
+        g_return_if_fail(foreground != nullptr);
+        g_return_if_fail(valid_color(foreground));
+
         IMPL(terminal)->set_color_foreground(vte::color::rgb(foreground));
 }
 
@@ -2795,6 +2810,7 @@ vte_terminal_set_color_highlight(VteTerminal *terminal,
                                  const GdkRGBA *highlight_background)
 {
         g_return_if_fail(VTE_IS_TERMINAL(terminal));
+        g_return_if_fail(highlight_background == nullptr || valid_color(highlight_background));
 
         auto impl = IMPL(terminal);
         if (highlight_background)
@@ -2818,6 +2834,7 @@ vte_terminal_set_color_highlight_foreground(VteTerminal *terminal,
                                             const GdkRGBA *highlight_foreground)
 {
         g_return_if_fail(VTE_IS_TERMINAL(terminal));
+        g_return_if_fail(highlight_foreground == nullptr || valid_color(highlight_foreground));
 
         auto impl = IMPL(terminal);
         if (highlight_foreground)
@@ -2857,6 +2874,10 @@ vte_terminal_set_colors(VteTerminal *terminal,
                         (palette_size == 16) ||
                         (palette_size == 232) ||
                         (palette_size == 256));
+        g_return_if_fail(foreground == nullptr || valid_color(foreground));
+        g_return_if_fail(background == nullptr || valid_color(background));
+        for (gsize i = 0; i < palette_size; ++i)
+                g_return_if_fail(valid_color(&palette[i]));
 
         vte::color::rgb fg;
         if (foreground)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]