HomeFreeBSD

Fix improper null-byte termination handling

Description

Fix improper null-byte termination handling

Fix a few cases where null-byte termination of strings was done
unnecessarily or incorrectly.

  • The snprintf() function always produces a null-byte terminated string for non-negative return values, so it is not necessary to write out a null-byte as a separate step.
  • Also, it is unsafe to use the return value of snprintf() as an offset for placing a null-byte, because if the output was truncated the return value is the number of bytes that _would_ have been written had enough space been available. Therefore the return value may index beyond the array boundaries.
  • Finally, snprintf() accounts for the null-byte when limiting its output size, so there is no need to pass it a size parameter that is one less than the buffer size.

Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #2875

Details

Provenance
Ned Bass <bass6@llnl.gov>Authored on Nov 7 2014, 2:18 AM
Brian Behlendorf <behlendorf1@llnl.gov>Committed on Nov 17 2014, 11:28 PM
Parents
rG89b1cd658152: Prevent ZFS leaking pool free space
Branches
Unknown
Tags
Unknown