Increase buffer size due to warning from ToT GCC

Message ID 1513356200.23720.6.camel@cavium.com
State New, archived
Headers

Commit Message

Steve Ellcey Dec. 15, 2017, 4:43 p.m. UTC
  I ran into another error while building ToT glibc with ToT GCC.

dbg_log.c: In function ‘dbg_log’:
dbg_log.c:71:46: error: ‘%s’ directive output may be truncated writing up to 511 bytes into a region of size between 241 and 506 [-Werror=format-truncation=]
       snprintf (msg, sizeof (msg), "%s - %d: %s%s", buf, getpid (), msg2,
                                              ^~                     ~~~~
In file included from ../libio/stdio.h:862,
                 from ../include/stdio.h:2,
                 from dbg_log.c:19:
../libio/bits/stdio2.h:64:10: note: ‘__builtin___snprintf_chk’ output between 7 and 784 bytes into a destination of size 512
   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        __bos (__s), __fmt, __va_arg_pack ());
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
../o-iterator.mk:9: recipe for target '/home/sellcey/tot/obj/glibc64/nscd/dbg_log.o' failed
make[2]: *** [/home/sellcey/tot/obj/glibc64/nscd/dbg_log.o] Error 1


Here is a patch to fix it, OK to checkin?


2017-12-15  Steve Ellcey  <sellcey@cavium.com>

	* nscd/dbg_log.c (dbg_log): Increase msg buffer size.
  

Comments

Joseph Myers Dec. 15, 2017, 4:59 p.m. UTC | #1
On Fri, 15 Dec 2017, Steve Ellcey wrote:

> Here is a patch to fix it, OK to checkin?

OK.  (I doubt there would actually be truncation here, but it's 
locale-dependent, so making this buffer large enough to ensure that only 
the previous format operations can result in truncation, and this one 
can't, seems reasonable.)
  

Patch

diff --git a/nscd/dbg_log.c b/nscd/dbg_log.c
index d4b19ac..2190c16 100644
--- a/nscd/dbg_log.c
+++ b/nscd/dbg_log.c
@@ -67,7 +67,7 @@  dbg_log (const char *fmt,...)
       char buf[256];
       strftime (buf, sizeof (buf), "%c", &now);
 
-      char msg[512];
+      char msg[1024];
       snprintf (msg, sizeof (msg), "%s - %d: %s%s", buf, getpid (), msg2,
 		msg2[strlen (msg2) - 1] == '\n' ? "" : "\n");
       if (dbgout)