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 681501 - gmem: array only partially filled with memcpy
gmem: array only partially filled with memcpy
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.33.x
Other All
: Normal trivial
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-08-09 09:11 UTC by Thomas Andersen
Modified: 2012-08-20 14:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Reduce the size of local_data (954 bytes, patch)
2012-08-09 09:15 UTC, Thomas Andersen
committed Details | Review

Description Thomas Andersen 2012-08-09 09:11:48 UTC
PVS-Studio spotted a memcpy that only partially fills the target array.

In g_mem_profile:
http://git.gnome.org/browse/glib/tree/glib/gmem.c#n714

The size of the array for local_data is calculated as:
guint local_data[(MEM_PROFILE_TABLE_SIZE + 1) * 8 * sizeof (profile_data[0])];
(which looks a bit odd)

The memcpy uses same calculation, but for n bytes to copy:
memcpy (local_data, profile_data, (MEM_PROFILE_TABLE_SIZE + 1) * 8 * sizeof (profile_data[0]));
which will underflow the array.

I will attach a patch that sets the size of local_data as:
guint local_data[(MEM_PROFILE_TABLE_SIZE + 1) * 8];

The originally code was added in this commit:
http://git.gnome.org/browse/glib/commit/glib/gmem.c?id=782a8e2e7c69c3d98bd69bcfdbb65ded520576f4
Comment 1 Thomas Andersen 2012-08-09 09:15:48 UTC
Created attachment 220767 [details] [review]
Reduce the size of local_data
Comment 2 Matthias Clasen 2012-08-17 04:02:32 UTC
Review of attachment 220767 [details] [review]:

Looks right to me.
Comment 3 Thomas Andersen 2012-08-20 14:47:02 UTC
Comment on attachment 220767 [details] [review]
Reduce the size of local_data

Committed to master:
http://git.gnome.org/browse/glib/commit/?id=96a0c589eec8e66f0d879c2a0979df6fd2c23dde