After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 691836 - Invalid read of size 4 at gdk_x11_screen_get_monitor_workarea
Invalid read of size 4 at gdk_x11_screen_get_monitor_workarea
Status: RESOLVED DUPLICATE of bug 691426
Product: gtk+
Classification: Platform
Component: Backend: X11
3.4.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2013-01-16 09:58 UTC by Paul Menzel
Modified: 2013-03-23 02:20 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Paul Menzel 2013-01-16 09:58:54 UTC
Using Debian Sid/unstable with libgtk-3-0 3.4.2-5 and running Evolution 3.4.4 under Valgrind

    $ G_SLICE=always-malloc G_DEBUG=gc-friendly valgrind -v --tool=memcheck --leak-check=full --num-callers=50 --suppressions=valgrind-python.supp --log-file=/tmp/20130115--evolution-valgrind.log evolution

I see the following errors reported.

        ==17582== 15 errors in context 31 of 11139:
        ==17582== Invalid read of size 4
        ==17582==    at 0x5DC514D: gdk_x11_screen_get_monitor_workarea (gdkscreen-x11.c:362)
        ==17582==  Address 0x2ade3b14 is 11 bytes after a block of size 17 alloc'd
        ==17582==    at 0x48288D8: malloc (vg_replace_malloc.c:270)
        ==17582==    by 0x5EB0FE7: XGetWindowProperty (GetProp.c:96)
        ==17582==    by 0x5DC5043: gdk_x11_screen_get_monitor_workarea (gdkscreen-x11.c:337)
        ==17582== 
        ==17582== 
        ==17582== 15 errors in context 32 of 11139:
        ==17582== Invalid read of size 4
        ==17582==    at 0x5DC5145: gdk_x11_screen_get_monitor_workarea (gdkscreen-x11.c:361)
        ==17582==  Address 0x2ade3b10 is 7 bytes after a block of size 17 alloc'd
        ==17582==    at 0x48288D8: malloc (vg_replace_malloc.c:270)
        ==17582==    by 0x5EB0FE7: XGetWindowProperty (GetProp.c:96)
        ==17582==    by 0x5DC5043: gdk_x11_screen_get_monitor_workarea (gdkscreen-x11.c:337)
        ==17582== 
        ==17582== 
        ==17582== 15 errors in context 33 of 11139:
        ==17582== Invalid read of size 4
        ==17582==    at 0x5DC513D: gdk_x11_screen_get_monitor_workarea (gdkscreen-x11.c:360)
        ==17582==  Address 0x2ade3b0c is 3 bytes after a block of size 17 alloc'd
        ==17582==    at 0x48288D8: malloc (vg_replace_malloc.c:270)
        ==17582==    by 0x5EB0FE7: XGetWindowProperty (GetProp.c:96)
        ==17582==    by 0x5DC5043: gdk_x11_screen_get_monitor_workarea (gdkscreen-x11.c:337)
        ==17582== 
        ==17582== 
        ==17582== 15 errors in context 34 of 11139:
        ==17582== Invalid read of size 4
        ==17582==    at 0x5DC5136: gdk_x11_screen_get_monitor_workarea (gdkscreen-x11.c:359)
        ==17582==  Address 0x2ade3b08 is 16 bytes inside a block of size 17 alloc'd
        ==17582==    at 0x48288D8: malloc (vg_replace_malloc.c:270)
        ==17582==    by 0x5EB0FE7: XGetWindowProperty (GetProp.c:96)
        ==17582==    by 0x5DC5043: gdk_x11_screen_get_monitor_workarea (gdkscreen-x11.c:337)

The code is the following,

        static void
        get_work_area (GdkScreen    *screen,
                       GdkRectangle *area)
        {
          Atom            workarea;
          Atom            type;
          Window          win;
          int             format;
          gulong          num;
          gulong          leftovers;
          gulong          max_len = 4 * 32;
          guchar         *ret_workarea;
          long           *workareas;
          int             result;
          int             disp_screen;
          int             desktop;
          Display        *display;

          display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (screen));
          disp_screen = GDK_SCREEN_XNUMBER (screen);
          workarea = XInternAtom (display, "_NET_WORKAREA", True);

          /* Defaults in case of error */
          area->x = 0;
          area->y = 0;
          area->width = gdk_screen_get_width (screen);
          area->height = gdk_screen_get_height (screen);

          if (workarea == None)
            return;

          win = XRootWindow (display, disp_screen);
→ l 337 result = XGetWindowProperty (display,
                                       win,
                                       workarea,
                                       0,
                                       max_len,
                                       False,
                                       AnyPropertyType,
                                       &type,
                                       &format,
                                       &num,
                                       &leftovers,
                                       &ret_workarea);
          if (result != Success ||
              type == None ||
              format == 0 ||
              leftovers ||
              num % 4 != 0)
            return;

          desktop = get_current_desktop (screen);

          workareas = (long *) ret_workarea;
→ l 359 area->x = workareas[desktop * 4];
          area->y = workareas[desktop * 4 + 1];
          area->width = workareas[desktop * 4 + 2];
          area->height = workareas[desktop * 4 + 3];

          XFree (ret_workarea);
        }

and the invalid reads happen in the last lines.

359          area->x = workareas[desktop * 4];
360          area->y = workareas[desktop * 4 + 1];
370          area->width = workareas[desktop * 4 + 2];
380          area->height = workareas[desktop * 4 + 3];

There is one commit in the branch `master` touching that code [1], though I think it is unrelated.

commit 2fcbe3a9b44491059170b71f75e07b3b24138c4a
Author: Geoff Reedy <geoff@programmer-monk.net>
Date:   Wed Jan 9 21:40:04 2013 -0700

    x11: add missing checks that a hint is supported
    
    Before acting on any hint that is set by the window manager we must
    first check that the hint is supported by the current window manager.
    Checking that a property has a value is insufficient as it may have
    been set by a previous window manager which did support the hint.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=691515

[1] http://git.gnome.org/browse/gtk+/commit/?id=2fcbe3a9b44491059170b71f75e07b3b24138c4a
Comment 1 Matthias Clasen 2013-03-23 02:20:20 UTC

*** This bug has been marked as a duplicate of bug 691426 ***