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 552505 - gcc attribute alloc_size markup
gcc attribute alloc_size markup
Status: RESOLVED FIXED
Product: libxml2
Classification: Platform
Component: general
2.7.1
Other All
: Normal enhancement
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2008-09-16 14:38 UTC by Marcus Meissner
Modified: 2009-01-18 17:27 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
libxml2-2.7.1-alloc_size.patch (1.77 KB, patch)
2008-09-16 14:39 UTC, Marcus Meissner
none Details | Review

Description Marcus Meissner 2008-09-16 14:38:12 UTC
Following patch adds gcc attribute alloc_size markup to libxml2 allocator
functions. For at-compile-time known sized allocations the compiler tracks the
size of the pointer and can utilize overflow checking in standard mem* and str* functions.

This feature has appearewd with gcc 4.3
Comment 1 Marcus Meissner 2008-09-16 14:39:02 UTC
Created attachment 118826 [details] [review]
libxml2-2.7.1-alloc_size.patch

patch to add allocsize markup
Comment 2 Daniel Veillard 2008-09-30 16:15:40 UTC
Hi Marcus,

okay that's interesting but I'm a bit confused:

http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html

seems to indicate it's useful only if __builtin_object_size
is being used, and I don't use it in libxml2 code, so I'm
wondering a bit about the actual use of the patch just by
itself. Could you explain a bit ?

  thanks,

Daniel
Comment 3 Marcus Meissner 2008-10-01 13:46:52 UTC
what happens is that the memcpy() memmove() strcpy() etc. standard libc
functions use __builtin_objectg_size() internally.


So if you allocate a at compile time known sized buffer and use one of the
mem* or str* functions with such a known sized destination buffer, it will 
check its size and abort() if the operation would overflow.

Not sure though if you ever allocate compile-time-known sized buffers with those functions or if they are ever passed into mem* or str* functions.
Comment 4 Daniel Veillard 2009-01-18 17:27:59 UTC
Okay, applied thanks !
I had to also fix the apibuild generator to handle the new
extension, but that looks fine and is now commited to SVN,

  thanks,

Daniel