[parted-devel] [PATCH 84/86] Fix the length of several strncpy calls

Phillip Susi psusi at ubuntu.com
Wed Jul 25 14:04:28 BST 2018


On 7/24/2018 7:04 PM, Brian C. Lane wrote:
>> strncpy doesn't fill the remainder with zeros, and if it runs out of
>> space, leaves the string unterminated, so you have to manually set the
>> last byte of the buffer to zero.
> 
> Not according to the manpage for strncpy on Fedora 28:
> 
> "If the length of src is less than n, strncpy() writes additional null
> bytes to dest to ensure that a total of n bytes are written."

Ahh, missed that part.  But the important part is this:

Warning: If there is no null byte among the first n bytes of src, the
string placed in dest will not  be  null-terminated.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <http://alioth-lists.debian.net/pipermail/parted-devel/attachments/20180725/7c3c7f0b/attachment.sig>


More information about the parted-devel mailing list