[gtk/pvs-fixes: 9/11] a11y: Avoid out-of-bounds access




commit aa5bd38137fb11e068eb8a4759cc91fbef9c5830
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Feb 4 00:34:05 2021 -0500

    a11y: Avoid out-of-bounds access
    
    Don't use the index before we've checked its good.
    
    Pointed out in https://www.viva64.com/en/b/0793/

 gtk/a11y/gtkatspiaction.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
---
diff --git a/gtk/a11y/gtkatspiaction.c b/gtk/a11y/gtkatspiaction.c
index fb39abf8d5..d31cda147b 100644
--- a/gtk/a11y/gtkatspiaction.c
+++ b/gtk/a11y/gtkatspiaction.c
@@ -68,10 +68,8 @@ action_handle_method (GtkAtSpiContext        *self,
 
       g_variant_get (parameters, "(i)", &idx);
 
-      const Action *action = &actions[idx];
-
       if (idx >= 0 && idx < n_actions)
-        g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", action->name));
+        g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", actions[idx].name));
       else
         g_dbus_method_invocation_return_error (invocation,
                                                G_IO_ERROR,
@@ -129,10 +127,8 @@ action_handle_method (GtkAtSpiContext        *self,
 
       g_variant_get (parameters, "(i)", &idx);
 
-      const Action *action = &actions[idx];
-
       if (idx >= 0 && idx < n_actions)
-        g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", action->keybinding));
+        g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", actions[idx].keybinding));
       else
         g_dbus_method_invocation_return_error (invocation,
                                                G_IO_ERROR,


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