New warning from NetBSD 9.0

Eric S. Raymond esr at thyrsus.com
Wed Feb 19 13:19:55 UTC 2020


Hal Murray via devel <devel at ntpsec.org>:
> 
> NetBSD just released version 9.0.  It now generates this warning:
> 
> ../../ntpd/ntp_control.c:1476:34: warning: '%s' directive output may be 
> truncated writing up to 255 bytes into a region of size between 0 and 255 
> [-Wformat-truncation=]
> 
>         char str[256];
> 
>                 snprintf(str, sizeof(str), "%s/%s", utsnamebuf.sysname,
>                          utsnamebuf.release);
> 
> Has anybody seen this before and/or know how to fix it?

I've seen it before.  Rarely.

If your format string had only a single %s in it, you could fix it by
adding a precision specifier to the string (not a length specifier, a
*precision* specifier) which bounds the amount of bytes theb snprinf
can write into the buffer.

I guess you could give both %s-cookies a precision specifier of 128.
-- 
		<a href="http://www.catb.org/~esr/">Eric S. Raymond</a>




More information about the devel mailing list