Skip to contentSkip to conversation

critical bug in strncpy() - solved

KJ walter harms 1 participant 1 message Mar 29, 2005 Kernel janitors

lore
Share & tools
lore
#0 lore raw

mea culpa,
for some odd reason i did not see "the dest will be padded with nulls." i will send a fix for the documentation to the mainling list.

re,
walter

Quoted 4 lines · Matthew Wilcox

There is no bug in lib/string.c's implementation of strncpy(). Most people do not realise that strncpy is a stupid function that is almost impossible to use correctly. Read the manpage:

Quoted 9 lines

The strncpy() function is similar, except that not more than n bytes of src are copied. Thus, if there is no null byte among the first n bytes of src, the result will not be null-terminated.

In the case where the length of src is less than that of n, the remain- der of dest will be padded with nulls.

This agrees with POSIX, ANSI C and Single Unix, fwiw.

_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors