Package: gcc-4.9
Version: 4.9.0-6

$ cat t.c
#define _FORTIFY_SOURCE 2
#include <stdio.h>
#include <limits.h>

long long size;

void execute(void) {
  unsigned char input[4096];
  size_t bytes = (size > (ssize_t)sizeof input
                  ? sizeof input
                  : size);
  size_t bytesRead = fread(input, 1, bytes, stdin);
}

int main(int argc, char **argv) {
  size = LLONG_MAX;
  execute();
  return 0;
}
$ gcc-4.9 -O2 t.c
$ gcc-4.9 -O2 -flto t.c
In function ‘__fread_alias’,
    inlined from ‘execute’ at t.c:12:10:
/usr/include/i386-linux-gnu/bits/stdio2.h:290:2: warning: call to ‘__fread_chk_warn’ declared with attribute warning: fread called with bigger size * nmemb than length of destination buffer
  return __fread_chk (__ptr, __bos0 (__ptr), __size, __n, __stream);
  ^


richard@deodand:~/src/vbig$ dpkg -l libc6-dev gcc-4.9
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version      Architecture Description
+++-==============-============-============-=================================
ii  gcc-4.9        4.9.0-6      i386         GNU C compiler
ii libc6-dev:i386 2.19-1 i386 Embedded GNU C Library: Developme

The relevant portion of stdio2.h is:

   266  extern size_t __fread_chk (void *__restrict __ptr, size_t __ptrlen,
   267                             size_t __size, size_t __n,
   268                             FILE *__restrict __stream) __wur;
   269  extern size_t __REDIRECT (__fread_alias,
   270                            (void *__restrict __ptr, size_t __size,
   271                             size_t __n, FILE *__restrict __stream),
   272                            fread) __wur;
   273  extern size_t __REDIRECT (__fread_chk_warn,
   274                            (void *__restrict __ptr, size_t __ptrlen,
   275                             size_t __size, size_t __n,
   276                             FILE *__restrict __stream),
   277                            __fread_chk)
278 __wur __warnattr ("fread called with bigger size * nmemb than length "
   279                         "of destination buffer");
   280
   281  __fortify_function __wur size_t
   282  fread (void *__restrict __ptr, size_t __size, size_t __n,
   283         FILE *__restrict __stream)
   284  {
   285    if (__bos0 (__ptr) != (size_t) -1)
   286      {
   287        if (!__builtin_constant_p (__size)
   288            || !__builtin_constant_p (__n)
289 || (__size | __n) >= (((size_t) 1) << (8 * sizeof (size_t) / 2))) 290 return __fread_chk (__ptr, __bos0 (__ptr), __size, __n, __stream);
   291
   292        if (__size * __n > __bos0 (__ptr))
293 return __fread_chk_warn (__ptr, __bos0 (__ptr), __size, __n, __stream);
   294      }
   295    return __fread_alias (__ptr, __size, __n, __stream);
   296  }

The warning attribute is attached to __fread_chk_warn (called line 293) but the warning is issued against line 290 where __fread_chk is called - so the compiler has got confused about these two functions?

ttfn/rjk


--
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to