summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTony Hutter <[email protected]>2018-04-04 10:16:47 -0700
committerBrian Behlendorf <[email protected]>2018-04-04 10:16:47 -0700
commit21a4f5cc867b4f166704df84985edc048caa2578 (patch)
tree18eb614a113f6a16c9ab5cd3c8247f2230b33cea /lib
parent1724eb62debfaa48f5861660615d49a994945d94 (diff)
Fedora 28: Fix misc bounds check compiler warnings
Fix a bunch of (mostly) sprintf/snprintf truncation compiler warnings that show up on Fedora 28 (GCC 8.0.1). Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Tony Hutter <[email protected]> Closes #7361 Closes #7368
Diffstat (limited to 'lib')
-rw-r--r--lib/libspl/include/umem.h2
-rw-r--r--lib/libzfs/libzfs_dataset.c14
-rw-r--r--lib/libzfs/libzfs_sendrecv.c2
3 files changed, 13 insertions, 5 deletions
diff --git a/lib/libspl/include/umem.h b/lib/libspl/include/umem.h
index c63026cee..5b10ac801 100644
--- a/lib/libspl/include/umem.h
+++ b/lib/libspl/include/umem.h
@@ -146,7 +146,7 @@ umem_cache_create(
cp = umem_alloc(sizeof (umem_cache_t), UMEM_DEFAULT);
if (cp) {
- strncpy(cp->cache_name, name, UMEM_CACHE_NAMELEN);
+ strlcpy(cp->cache_name, name, UMEM_CACHE_NAMELEN);
cp->cache_bufsize = bufsize;
cp->cache_align = align;
cp->cache_constructor = constructor;
diff --git a/lib/libzfs/libzfs_dataset.c b/lib/libzfs/libzfs_dataset.c
index 17c17fa79..8ec5b7af4 100644
--- a/lib/libzfs/libzfs_dataset.c
+++ b/lib/libzfs/libzfs_dataset.c
@@ -1032,10 +1032,11 @@ zfs_valid_proplist(libzfs_handle_t *hdl, zfs_type_t type, nvlist_t *nvl,
if (prop == ZPROP_INVAL && zfs_prop_userquota(propname)) {
zfs_userquota_prop_t uqtype;
- char newpropname[128];
+ char *newpropname = NULL;
char domain[128];
uint64_t rid;
uint64_t valary[3];
+ int rc;
if (userquota_propname_decode(propname, zoned,
&uqtype, domain, sizeof (domain), &rid) != 0) {
@@ -1092,17 +1093,24 @@ zfs_valid_proplist(libzfs_handle_t *hdl, zfs_type_t type, nvlist_t *nvl,
* userquota@<hex-rid>-domain, to make it easy
* for the kernel to decode.
*/
- (void) snprintf(newpropname, sizeof (newpropname),
- "%s%llx-%s", zfs_userquota_prop_prefixes[uqtype],
+ rc = asprintf(&newpropname, "%s%llx-%s",
+ zfs_userquota_prop_prefixes[uqtype],
(longlong_t)rid, domain);
+ if (rc == -1 || newpropname == NULL) {
+ (void) no_memory(hdl);
+ goto error;
+ }
+
valary[0] = uqtype;
valary[1] = rid;
valary[2] = intval;
if (nvlist_add_uint64_array(ret, newpropname,
valary, 3) != 0) {
+ free(newpropname);
(void) no_memory(hdl);
goto error;
}
+ free(newpropname);
continue;
} else if (prop == ZPROP_INVAL && zfs_prop_written(propname)) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
diff --git a/lib/libzfs/libzfs_sendrecv.c b/lib/libzfs/libzfs_sendrecv.c
index 1623a75b4..b138745b8 100644
--- a/lib/libzfs/libzfs_sendrecv.c
+++ b/lib/libzfs/libzfs_sendrecv.c
@@ -3758,7 +3758,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap,
* Determine the name of the origin snapshot.
*/
if (originsnap) {
- (void) strncpy(origin, originsnap, sizeof (origin));
+ (void) strlcpy(origin, originsnap, sizeof (origin));
if (flags->verbose)
(void) printf("using provided clone origin %s\n",
origin);