From c9e319faae9677aa0dddfbf9973b9e8fc3feb06c Mon Sep 17 00:00:00 2001 From: Jorgen Lundman Date: Mon, 8 Jun 2020 03:42:12 +0900 Subject: Replace sprintf()->snprintf() and strcpy()->strlcpy() The strcpy() and sprintf() functions are deprecated on some platforms. Care is needed to ensure correct size is used. If some platforms miss snprintf, we can add a #define to sprintf, likewise strlcpy(). The biggest change is adding a size parameter to zfs_id_to_fuidstr(). The various *_impl_get() functions are only used on linux and have not yet been updated. Reviewed by: Sean Eric Fagan Reviewed-by: Brian Behlendorf Signed-off-by: Jorgen Lundman Closes #10400 --- module/zfs/zfs_quota.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'module/zfs/zfs_quota.c') diff --git a/module/zfs/zfs_quota.c b/module/zfs/zfs_quota.c index 1acfbf1ea..6c83f79c9 100644 --- a/module/zfs/zfs_quota.c +++ b/module/zfs/zfs_quota.c @@ -269,7 +269,8 @@ zfs_userspace_one(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type, offset = DMU_OBJACCT_PREFIX_LEN; } - err = zfs_id_to_fuidstr(zfsvfs, domain, rid, buf + offset, B_FALSE); + err = zfs_id_to_fuidstr(zfsvfs, domain, rid, buf + offset, + sizeof (buf) - offset, B_FALSE); if (err) return (err); @@ -325,7 +326,7 @@ zfs_set_userquota(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type, return (SET_ERROR(EINVAL)); } - err = zfs_id_to_fuidstr(zfsvfs, domain, rid, buf, B_TRUE); + err = zfs_id_to_fuidstr(zfsvfs, domain, rid, buf, sizeof (buf), B_TRUE); if (err) return (err); fuid_dirtied = zfsvfs->z_fuid_dirty; @@ -407,12 +408,13 @@ zfs_id_overobjquota(zfsvfs_t *zfsvfs, uint64_t usedobj, uint64_t id) if (quotaobj == 0 || zfsvfs->z_replay) return (B_FALSE); - (void) sprintf(buf, "%llx", (longlong_t)id); + (void) snprintf(buf, sizeof (buf), "%llx", (longlong_t)id); err = zap_lookup(zfsvfs->z_os, quotaobj, buf, 8, 1, "a); if (err != 0) return (B_FALSE); - (void) sprintf(buf, DMU_OBJACCT_PREFIX "%llx", (longlong_t)id); + (void) snprintf(buf, sizeof (buf), DMU_OBJACCT_PREFIX "%llx", + (longlong_t)id); err = zap_lookup(zfsvfs->z_os, usedobj, buf, 8, 1, &used); if (err != 0) return (B_FALSE); @@ -448,7 +450,7 @@ zfs_id_overblockquota(zfsvfs_t *zfsvfs, uint64_t usedobj, uint64_t id) if (quotaobj == 0 || zfsvfs->z_replay) return (B_FALSE); - (void) sprintf(buf, "%llx", (longlong_t)id); + (void) snprintf(buf, sizeof (buf), "%llx", (longlong_t)id); err = zap_lookup(zfsvfs->z_os, quotaobj, buf, 8, 1, "a); if (err != 0) return (B_FALSE); -- cgit v1.2.3