New read etc. checking macros
Jakub Jelinek
jakub@redhat.com
Sat Feb 26 00:50:00 GMT 2005
On Fri, Feb 25, 2005 at 04:46:42PM -0800, Roland McGrath wrote:
> > Yeah, I think we can only protect read etc. with _FORTIFY_SOURCE >= 2
> > which has some limitations against POSIX and not allowing bigger len
> > than the buffer that is provided is reasonable limitation.
>
> Does the gcc magic handle cases like:
>
> struct {
> uint32_t magic;
> char foo[3];
> char bar[27];
> } record;
>
> if (read(fd, &record.magic, sizeof record.magic) == sizeof record.magic &&
> record.magic == 0x1234567)
> n = read(fd, &record.foo, sizeof record - (&record.foo - (char*)&record));
>
> i.e., so __bos yields 30 rather than 3?
__bos (&record.foo) is 3 for -D_FORTIFY_SOURCE=2, and 30 for
-D_FORTIFY_SOURCE=1. So read etc. probably wants to use __bos0
(&record.foo) which is always 30.
Jakub
More information about the Libc-hacker
mailing list