[parted-devel] [PATCH 84/86] Fix the length of several strncpy calls
Brian C. Lane
bcl at redhat.com
Wed Jul 25 00:04:01 BST 2018
On Tue, Jul 24, 2018 at 09:15:44AM -0400, Phillip Susi wrote:
> On 7/23/2018 8:26 PM, Brian C. Lane wrote:
> > These need to be 1 less than the allocated size of the buffer, strncpy
> > will fill the remainder with zeros, but there needs to be room for at
> > least one 0x00 at the end.
>
> 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."
--
Brian C. Lane (PST8PDT)
More information about the parted-devel
mailing list