diff mbox

[Doc] Add caveat to __builtin_object_size

Message ID 4FCC6EA7.4060507@redhat.com
State New
Headers show

Commit Message

Florian Weimer June 4, 2012, 8:15 a.m. UTC
This patch adds a cross-reference to GNU libc and _FORTIFY_SOURCE (which 
needs to be documented there) and mentions the optimization level 
requirements.

Okay for trunk?

2012-06-04  Florian Weimer  <fweimer@redhat.com>

	* doc/extend.texi (Object Size Checking): Mention
          _FORTIFY_SOURCE, add caveat.

Comments

Jakub Jelinek June 4, 2012, 8:23 a.m. UTC | #1
On Mon, Jun 04, 2012 at 10:15:35AM +0200, Florian Weimer wrote:
> --- gcc/doc/extend.texi	(revision 187951)
> +++ gcc/doc/extend.texi	(working copy)
> @@ -7376,8 +7376,15 @@
>  @findex __builtin___vfprintf_chk
>  
>  GCC implements a limited buffer overflow protection mechanism
> -that can prevent some buffer overflow attacks.
> +that can prevent some buffer overflow attacks.  GNU libc uses it
> +in the implementation of the @code{_FORTIFY_SOURCE} functionality.
>  
> +This protection mechanism is only a last resort.  As a programmer, you
> +must not rely on its presence, but use explicit buffer length checks
> +to avoid buffer overflows.  GCC may not be able to determine buffer
> +sizes accurately, and the accuracy depends on compiler version and
> +optimization level (currently, at least @option{-O2} is required).

That isn't true, at -O1 or -Os it should work just fine too, and
to some extent on the compiler side even at -O0.
So I'd just replace optimization level.*\. with compiler options.

	Jakub
diff mbox

Patch

Index: gcc/doc/extend.texi
===================================================================
--- gcc/doc/extend.texi	(revision 187951)
+++ gcc/doc/extend.texi	(working copy)
@@ -7376,8 +7376,15 @@ 
 @findex __builtin___vfprintf_chk
 
 GCC implements a limited buffer overflow protection mechanism
-that can prevent some buffer overflow attacks.
+that can prevent some buffer overflow attacks.  GNU libc uses it
+in the implementation of the @code{_FORTIFY_SOURCE} functionality.
 
+This protection mechanism is only a last resort.  As a programmer, you
+must not rely on its presence, but use explicit buffer length checks
+to avoid buffer overflows.  GCC may not be able to determine buffer
+sizes accurately, and the accuracy depends on compiler version and
+optimization level (currently, at least @option{-O2} is required).
+
 @deftypefn {Built-in Function} {size_t} __builtin_object_size (void * @var{ptr}, int @var{type})
 is a built-in construct that returns a constant number of bytes from
 @var{ptr} to the end of the object @var{ptr} pointer points to