New read etc. checking macros

Roland McGrath roland@redhat.com
Sat Feb 26 00:46:00 GMT 2005


> 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?



More information about the Libc-hacker mailing list