changeset 2199:8ee74cf778cb

GTK: Increase number buffers to 25 bytes to make sure they can store an unsigned long value and make sure they are zeroed out. This fixes warnings from gcc fortify, and improves safety.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 26 Oct 2020 23:05:20 +0000
parents e66bc47eec34
children 319eeecb411e
files gtk/dw.c gtk3/dw.c
diffstat 2 files changed, 27 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/gtk/dw.c	Mon Oct 26 00:58:44 2020 +0000
+++ b/gtk/dw.c	Mon Oct 26 23:05:20 2020 +0000
@@ -3918,7 +3918,7 @@
       tmphandle=gtk_menu_item_new();
    else
    {
-      char numbuf[11] = {0};
+      char numbuf[25] = {0};
 
       if (check)
       {
@@ -3934,7 +3934,7 @@
          else
             tmphandle = gtk_check_menu_item_new_with_label(tempbuf);
          gtk_check_menu_item_set_show_toggle(GTK_CHECK_MENU_ITEM(tmphandle), TRUE);
-         snprintf(numbuf, 10, "%lu", id);
+         snprintf(numbuf, 24, "%lu", id);
          gtk_object_set_data(GTK_OBJECT(menu), numbuf, (gpointer)tmphandle);
       }
       else
@@ -3950,7 +3950,7 @@
          }
          else
             tmphandle=gtk_menu_item_new_with_label(tempbuf);
-         snprintf(numbuf, 10, "%lu", id);
+         snprintf(numbuf, 24, "%lu", id);
          gtk_object_set_data(GTK_OBJECT(menu), numbuf, (gpointer)tmphandle);
       }
    }
@@ -4026,7 +4026,7 @@
  */
 void dw_menu_item_set_check(HMENUI menu, unsigned long id, int check)
 {
-   char numbuf[11] = {0};
+   char numbuf[25] = {0};
    GtkWidget *tmphandle;
    int _locked_by_me = FALSE;
 
@@ -4034,7 +4034,7 @@
       return;
 
    DW_MUTEX_LOCK;
-   snprintf(numbuf, 10, "%lu", id);
+   snprintf(numbuf, 24, "%lu", id);
    tmphandle = _find_submenu_id(menu, numbuf);
 
    if(tmphandle)
@@ -4056,7 +4056,7 @@
  */
 void dw_menu_item_set_state(HMENUI menu, unsigned long id, unsigned long state)
 {
-   char numbuf[11] = {0};
+   char numbuf[25] = {0};
    GtkWidget *tmphandle;
    int check;
    int _locked_by_me = FALSE;
@@ -4065,7 +4065,7 @@
       return;
 
    DW_MUTEX_LOCK;
-   snprintf(numbuf, 10, "%lu", id);
+   snprintf(numbuf, 24, "%lu", id);
    tmphandle = _find_submenu_id(menu, numbuf);
 
    if ( (state & DW_MIS_CHECKED) || (state & DW_MIS_UNCHECKED) )
@@ -4108,7 +4108,7 @@
  */
 int API dw_menu_delete_item(HMENUI menu, unsigned long id)
 {
-   char numbuf[11];
+   char numbuf[25] = {0};
    GtkWidget *tmphandle;
    int _locked_by_me = FALSE;
    int ret = DW_ERROR_UNKNOWN;
@@ -4117,7 +4117,7 @@
       return ret;
 
    DW_MUTEX_LOCK;
-   snprintf(numbuf, 10, "%lu", id);
+   snprintf(numbuf, 24, "%lu", id);
    tmphandle = _find_submenu_id(menu, numbuf);
 
    if(tmphandle)
@@ -4189,7 +4189,6 @@
 #ifdef GDK_WINDOWING_X11
 # if GTK_CHECK_VERSION(2,8,0)
    gdk_display_warp_pointer( gdk_display_get_default(), gdk_screen_get_default(), x, y );
-//   gdk_display_warp_pointer( GDK_DISPLAY(), gdk_screen_get_default(), x, y );
 # else
    XWarpPointer(GDK_DISPLAY(), None, GDK_ROOT_WINDOW(), 0,0,0,0, x, y);
 # endif
@@ -7338,7 +7337,7 @@
  */
 void _dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data, const char *text)
 {
-   char numbuf[11] = {0}, textbuffer[101] = {0};
+   char numbuf[25] = {0}, textbuffer[101] = {0};
    int flag = 0;
    GtkWidget *clist;
    int _locked_by_me = FALSE;
@@ -7351,7 +7350,7 @@
       return;
    }
 
-   snprintf(numbuf, 10, "%d", column);
+   snprintf(numbuf, 24, "%d", column);
    flag = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(clist), numbuf));
    if(pointer)
    {
@@ -7524,7 +7523,7 @@
  */
 int dw_container_get_column_type(HWND handle, int column)
 {
-   char numbuf[11] = {0};
+   char numbuf[25] = {0};
    int flag, rc;
    GtkWidget *clist;
    int _locked_by_me = FALSE;
@@ -7537,7 +7536,7 @@
       return 0;
    }
 
-   snprintf(numbuf, 10, "%d", column);
+   snprintf(numbuf, 24, "%d", column);
    flag = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(clist), numbuf));
 
    if(flag & DW_CFA_BITMAPORICON)
--- a/gtk3/dw.c	Mon Oct 26 00:58:44 2020 +0000
+++ b/gtk3/dw.c	Mon Oct 26 23:05:20 2020 +0000
@@ -3517,7 +3517,7 @@
       tmphandle=gtk_menu_item_new();
    else
    {
-      char numbuf[11] = {0};
+      char numbuf[25] = {0};
 
       if (check)
       {
@@ -3529,7 +3529,7 @@
             gtk_widget_add_accelerator(tmphandle, "activate", accel_group, tmp_key, GDK_MOD1_MASK, 0);
 #endif
          }
-         snprintf(numbuf, 10, "%lu", id);
+         snprintf(numbuf, 24, "%lu", id);
          g_object_set_data(G_OBJECT(menu), numbuf, (gpointer)tmphandle);
       }
       else
@@ -3542,7 +3542,7 @@
             gtk_widget_add_accelerator(tmphandle, "activate", accel_group, tmp_key, GDK_MOD1_MASK, 0);
 #endif
          }
-         snprintf(numbuf, 10, "%lu", id);
+         snprintf(numbuf, 24, "%lu", id);
          g_object_set_data(G_OBJECT(menu), numbuf, (gpointer)tmphandle);
       }
    }
@@ -3618,7 +3618,7 @@
  */
 void dw_menu_item_set_check(HMENUI menu, unsigned long id, int check)
 {
-   char numbuf[11];
+   char numbuf[25] = {0};
    GtkWidget *tmphandle;
    int _locked_by_me = FALSE;
 
@@ -3626,7 +3626,7 @@
       return;
 
    DW_MUTEX_LOCK;
-   snprintf(numbuf, 10, "%lu", id);
+   snprintf(numbuf, 24, "%lu", id);
    tmphandle = _find_submenu_id(menu, numbuf);
 
    if(tmphandle)
@@ -3648,7 +3648,7 @@
  */
 void dw_menu_item_set_state(HMENUI menu, unsigned long id, unsigned long state)
 {
-   char numbuf[11] = {0};
+   char numbuf[25] = {0};
    GtkWidget *tmphandle;
    int check;
    int _locked_by_me = FALSE;
@@ -3657,7 +3657,7 @@
       return;
 
    DW_MUTEX_LOCK;
-   snprintf(numbuf, 10, "%lu", id);
+   snprintf(numbuf, 24, "%lu", id);
    tmphandle = _find_submenu_id(menu, numbuf);
 
    if ( (state & DW_MIS_CHECKED) || (state & DW_MIS_UNCHECKED) )
@@ -3700,7 +3700,7 @@
  */
 int API dw_menu_delete_item(HMENUI menu, unsigned long id)
 {
-   char numbuf[11];
+   char numbuf[25] = {0};
    GtkWidget *tmphandle;
    int _locked_by_me = FALSE;
    int ret = DW_ERROR_UNKNOWN;
@@ -3709,7 +3709,7 @@
       return ret;
 
    DW_MUTEX_LOCK;
-   snprintf(numbuf, 10, "%lu", id);
+   snprintf(numbuf, 24, "%lu", id);
    tmphandle = _find_submenu_id(menu, numbuf);
 
    if(tmphandle)
@@ -5740,7 +5740,7 @@
 static int _dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator, int extra)
 {
    int z;
-   char numbuf[25];
+   char numbuf[25] = {0};
    GtkWidget *tree;
    GtkListStore *store;
    GtkTreeViewColumn *col;
@@ -6111,7 +6111,7 @@
  */
 void _dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data)
 {
-   char numbuf[21], textbuffer[101] = {0};
+   char numbuf[25] = {0}, textbuffer[101] = {0};
    int flag = 0;
    GtkWidget *cont;
    GtkListStore *store = NULL;
@@ -6128,7 +6128,7 @@
    {
       GtkTreeIter iter;
 
-      snprintf(numbuf, 20, "_dw_cont_col%d", column);
+      snprintf(numbuf, 24, "_dw_cont_col%d", column);
       flag = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cont), numbuf));
       if(pointer)
       {
@@ -6294,7 +6294,7 @@
  */
 int dw_container_get_column_type(HWND handle, int column)
 {
-   char numbuf[20];
+   char numbuf[25] = {0};
    int flag, rc = 0;
    GtkWidget *cont = handle;
    int _locked_by_me = FALSE;
@@ -6307,7 +6307,7 @@
       return 0;
    }
 
-   snprintf(numbuf, 20, "_dw_cont_col%d", column);
+   snprintf(numbuf, 24, "_dw_cont_col%d", column);
    flag = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cont), numbuf));
 
    if(flag & DW_CFA_BITMAPORICON)