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 <sef@ixsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Jorgen Lundman <lundman@lundman.net>
Closes #10400
This commit is contained in:
Jorgen Lundman
2020-06-08 03:42:12 +09:00
committed by GitHub
parent 60265072e0
commit c9e319faae
22 changed files with 79 additions and 60 deletions
+6 -5
View File
@@ -1870,14 +1870,15 @@ do_userquota_update(objset_t *os, userquota_cache_t *cache, uint64_t used,
if (subtract)
delta = -delta;
(void) sprintf(name, "%llx", (longlong_t)user);
(void) snprintf(name, sizeof (name), "%llx", (longlong_t)user);
userquota_update_cache(&cache->uqc_user_deltas, name, delta);
(void) sprintf(name, "%llx", (longlong_t)group);
(void) snprintf(name, sizeof (name), "%llx", (longlong_t)group);
userquota_update_cache(&cache->uqc_group_deltas, name, delta);
if (dmu_objset_projectquota_enabled(os)) {
(void) sprintf(name, "%llx", (longlong_t)project);
(void) snprintf(name, sizeof (name), "%llx",
(longlong_t)project);
userquota_update_cache(&cache->uqc_project_deltas,
name, delta);
}
@@ -2438,7 +2439,7 @@ dmu_snapshot_list_next(objset_t *os, int namelen, char *name,
return (SET_ERROR(ENAMETOOLONG));
}
(void) strcpy(name, attr.za_name);
(void) strlcpy(name, attr.za_name, namelen);
if (idp)
*idp = attr.za_first_integer;
if (case_conflict)
@@ -2483,7 +2484,7 @@ dmu_dir_list_next(objset_t *os, int namelen, char *name,
return (SET_ERROR(ENAMETOOLONG));
}
(void) strcpy(name, attr.za_name);
(void) strlcpy(name, attr.za_name, namelen);
if (idp)
*idp = attr.za_first_integer;
zap_cursor_advance(&cursor);