mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-11-18 02:20:59 +03:00
7584fbe846
Coverity found a bug in `zfs_secpolicy_create_clone()` where it is
possible for us to pass an unterminated string when `zfs_get_parent()`
returns an error. Upon inspection, it is clear that using `strlcpy()`
would have avoided this issue.
Looking at the codebase, there are a number of other uses of `strncpy()`
that are unsafe and even when it is used safely, switching to
`strlcpy()` would make the code more readable. Therefore, we switch all
instances where we use `strncpy()` to use `strlcpy()`.
Unfortunately, we do not portably have access to `strlcpy()` in
tests/zfs-tests/cmd/zfs_diff-socket.c because it does not link to
libspl. Modifying the appropriate Makefile.am to try to link to it
resulted in an error from the naming choice used in the file. Trying to
disable the check on the file did not work on FreeBSD because Clang
ignores `#undef` when a definition is provided by `-Dstrncpy(...)=...`.
We workaround that by explictly including the C file from libspl into
the test. This makes things build correctly everywhere.
We add a deprecation warning to `config/Rules.am` and suppress it on the
remaining `strncpy()` usage. `strlcpy()` is not portably avaliable in
tests/zfs-tests/cmd/zfs_diff-socket.c, so we use `snprintf()` there as a
substitute.
This patch does not tackle the related problem of `strcpy()`, which is
even less safe. Thankfully, a quick inspection found that it is used far
more correctly than strncpy() was used. A quick inspection did not find
any problems with `strcpy()` usage outside of zhack, but it should be
said that I only checked around 90% of them.
Lastly, some of the fields in kstat_t varied in size by 1 depending on
whether they were in userspace or in the kernel. The origin of this
discrepancy appears to be
|
||
---|---|---|
.. | ||
acl_impl.h | ||
acl.h | ||
atomic.h | ||
byteorder.h | ||
callb.h | ||
ccompat.h | ||
ccompile.h | ||
cmn_err.h | ||
condvar.h | ||
cred.h | ||
ctype.h | ||
debug.h | ||
dirent.h | ||
disp.h | ||
dkio.h | ||
fcntl.h | ||
file.h | ||
freebsd_rwlock.h | ||
idmap.h | ||
inttypes.h | ||
isa_defs.h | ||
kmem_cache.h | ||
kmem.h | ||
kstat.h | ||
list_impl.h | ||
list.h | ||
lock.h | ||
misc.h | ||
mod_os.h | ||
mode.h | ||
mount.h | ||
mutex.h | ||
param.h | ||
policy.h | ||
proc.h | ||
processor.h | ||
procfs_list.h | ||
random.h | ||
rwlock.h | ||
sdt.h | ||
sid.h | ||
sig.h | ||
simd_powerpc.h | ||
simd_x86.h | ||
simd.h | ||
spl_condvar.h | ||
string.h | ||
sunddi.h | ||
sysmacros.h | ||
systeminfo.h | ||
systm.h | ||
taskq.h | ||
thread.h | ||
time.h | ||
timer.h | ||
trace_zfs.h | ||
trace.h | ||
types32.h | ||
types.h | ||
uio.h | ||
uuid.h | ||
vfs.h | ||
vm.h | ||
vmsystm.h | ||
vnode_impl.h | ||
vnode.h | ||
wmsum.h | ||
zmod.h | ||
zone.h |