[PATCH] Replace strncpy with memccpy to fix -Wstringop-truncation.

Stefan Liebler stli@linux.vnet.ibm.com
Thu Apr 12 15:31:00 GMT 2018


On 04/05/2018 06:14 PM, Andreas Schwab wrote:
> On Apr 05 2018, Stefan Liebler <stli@linux.vnet.ibm.com> wrote:
> 
>> Why do we need the strncpy at all?
>> if (len == 0 && ...)
> 
> That's obviously a typo.
> 
> Andreas.
> 
Yes. You are right. Please have a look at the applied patch.
If the zero-termination is needed, numstr is copied to the buffer with 
strncpy and the zero-termination is applied.
If numstr is either 0 bytes long or the length of the numstr string is 
0, then _nss_nisplus_parse_pwent returns with 0.


This solves the mentioned warning with if build with gcc-head and 
--enable-obsolete-nsl.
But I can not test it as I don't have a nisplus setup.

Bye.
Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 20180412_nisplus-parser.patch
Type: text/x-patch
Size: 1388 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20180412/2360de82/attachment.bin>


More information about the Libc-alpha mailing list