summaryrefslogtreecommitdiffstats
path: root/lib/libzfs
diff options
context:
space:
mode:
authorTony Hutter <[email protected]>2017-06-28 10:05:16 -0700
committerBrian Behlendorf <[email protected]>2017-06-28 10:05:16 -0700
commit682ce104cdd80db4b67eea09eb0a90324c5f98ee (patch)
tree3fa2067633f5c089685600f25601af0f791bfcaf /lib/libzfs
parentcda0317e4d2a1277b328e4fc42ee3699bbe46c12 (diff)
GCC 7.1 fixes
GCC 7.1 with will warn when we're not checking the snprintf() return code in cases where the buffer could be truncated. This patch either checks the snprintf return code (where applicable), or simply disables the warnings (ztest.c). Reviewed-by: Chunwei Chen <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Tony Hutter <[email protected]> Closes #6253
Diffstat (limited to 'lib/libzfs')
-rw-r--r--lib/libzfs/libzfs_dataset.c22
-rw-r--r--lib/libzfs/libzfs_iter.c7
-rw-r--r--lib/libzfs/libzfs_sendrecv.c8
3 files changed, 25 insertions, 12 deletions
diff --git a/lib/libzfs/libzfs_dataset.c b/lib/libzfs/libzfs_dataset.c
index bc630919a..51c168ad7 100644
--- a/lib/libzfs/libzfs_dataset.c
+++ b/lib/libzfs/libzfs_dataset.c
@@ -3567,8 +3567,9 @@ zfs_check_snap_cb(zfs_handle_t *zhp, void *arg)
char name[ZFS_MAX_DATASET_NAME_LEN];
int rv = 0;
- (void) snprintf(name, sizeof (name),
- "%s@%s", zhp->zfs_name, dd->snapname);
+ if (snprintf(name, sizeof (name), "%s@%s", zhp->zfs_name,
+ dd->snapname) >= sizeof (name))
+ return (EINVAL);
if (lzc_exists(name))
verify(nvlist_add_boolean(dd->nvl, name) == 0);
@@ -3782,8 +3783,9 @@ zfs_snapshot_cb(zfs_handle_t *zhp, void *arg)
int rv = 0;
if (zfs_prop_get_int(zhp, ZFS_PROP_INCONSISTENT) == 0) {
- (void) snprintf(name, sizeof (name),
- "%s@%s", zfs_get_name(zhp), sd->sd_snapname);
+ if (snprintf(name, sizeof (name), "%s@%s", zfs_get_name(zhp),
+ sd->sd_snapname) >= sizeof (name))
+ return (EINVAL);
fnvlist_add_boolean(sd->sd_nvl, name);
@@ -4527,8 +4529,9 @@ zfs_hold_one(zfs_handle_t *zhp, void *arg)
char name[ZFS_MAX_DATASET_NAME_LEN];
int rv = 0;
- (void) snprintf(name, sizeof (name),
- "%s@%s", zhp->zfs_name, ha->snapname);
+ if (snprintf(name, sizeof (name), "%s@%s", zhp->zfs_name,
+ ha->snapname) >= sizeof (name))
+ return (EINVAL);
if (lzc_exists(name))
fnvlist_add_string(ha->nvl, name, ha->tag);
@@ -4647,8 +4650,11 @@ zfs_release_one(zfs_handle_t *zhp, void *arg)
int rv = 0;
nvlist_t *existing_holds;
- (void) snprintf(name, sizeof (name),
- "%s@%s", zhp->zfs_name, ha->snapname);
+ if (snprintf(name, sizeof (name), "%s@%s", zhp->zfs_name,
+ ha->snapname) >= sizeof (name)) {
+ ha->error = EINVAL;
+ rv = EINVAL;
+ }
if (lzc_get_holds(name, &existing_holds) != 0) {
ha->error = ENOENT;
diff --git a/lib/libzfs/libzfs_iter.c b/lib/libzfs/libzfs_iter.c
index d78c757a5..57ebdd89d 100644
--- a/lib/libzfs/libzfs_iter.c
+++ b/lib/libzfs/libzfs_iter.c
@@ -204,8 +204,11 @@ zfs_iter_bookmarks(zfs_handle_t *zhp, zfs_iter_f func, void *data)
bmark_name = nvpair_name(pair);
bmark_props = fnvpair_value_nvlist(pair);
- (void) snprintf(name, sizeof (name), "%s#%s", zhp->zfs_name,
- bmark_name);
+ if (snprintf(name, sizeof (name), "%s#%s", zhp->zfs_name,
+ bmark_name) >= sizeof (name)) {
+ err = EINVAL;
+ goto out;
+ }
nzhp = make_bookmark_handle(zhp, name, bmark_props);
if (nzhp == NULL)
diff --git a/lib/libzfs/libzfs_sendrecv.c b/lib/libzfs/libzfs_sendrecv.c
index 71ee8faae..ff909f1e3 100644
--- a/lib/libzfs/libzfs_sendrecv.c
+++ b/lib/libzfs/libzfs_sendrecv.c
@@ -1867,9 +1867,13 @@ zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap,
drr_versioninfo, DMU_COMPOUNDSTREAM);
DMU_SET_FEATUREFLAGS(drr.drr_u.drr_begin.
drr_versioninfo, featureflags);
- (void) snprintf(drr.drr_u.drr_begin.drr_toname,
+ if (snprintf(drr.drr_u.drr_begin.drr_toname,
sizeof (drr.drr_u.drr_begin.drr_toname),
- "%s@%s", zhp->zfs_name, tosnap);
+ "%s@%s", zhp->zfs_name, tosnap) >=
+ sizeof (drr.drr_u.drr_begin.drr_toname)) {
+ err = EINVAL;
+ goto stderr_out;
+ }
drr.drr_payloadlen = buflen;
err = dump_record(&drr, packbuf, buflen, &zc, outfd);