Bug 831 - workaround for spurious fread_chk warning against petal.c
workaround for spurious fread_chk warning against petal.c
Product: unbound
Classification: Unclassified
Component: server
Other All
: P5 enhancement
Assigned To: unbound team
Depends on:
  Show dependency treegraph
Reported: 2016-09-09 00:54 CEST by JINMEI Tatuya
Modified: 2016-09-09 07:55 CEST (History)
2 users (show)

See Also:

workaround patch (745 bytes, patch)
2016-09-09 00:54 CEST, JINMEI Tatuya
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description JINMEI Tatuya 2016-09-09 00:54:07 CEST
Created attachment 356 [details]
workaround patch

If I build unbound using my gcc (Ubuntu 5.4.0-6ubuntu1~16.04.2), it results in the following warning for testcode/petal.c:

In function ‘__fread_alias’,
    inlined from ‘provide_file_chunked’ at testcode/petal.c:476:49,
    inlined from ‘service_ssl’ at testcode/petal.c:551:7:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:290:9: 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);

As far as I can see this is a false positive, but from a quick look __fread_chk() doesn't seem to like to have a variable read size unrelated to the buffer size and complains about it.

Unfortunately this makes it impossible to build unbound with -Werror.  The attached patch will prevent the warning (and it should still be safe), although admittedly it's less efficient and unnecessarily complicated except for silencing a broken compiler.  Alternatively you could define tmpbuf as "char tmpbuf[avail-16]", which is simpler but relies on variable-length arrays.

I'd understand it if you consider it an unnecessary hack, but it would make my life much easier if you could adopt some workaround for this, whether it's the attached patch or not.
Comment 1 Wouter Wijngaards 2016-09-09 07:55:43 CEST

Applied the patch.  Thank you for reporting it!

Best regards, Wouter