mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
refactor: change dm_strncpy to dm_strncpy_check
For places where dm_strncpy is checked for result use inline wrapper dm_strncpy_check.
This commit is contained in:
parent
55f33d734f
commit
3777feb7a7
@ -452,7 +452,7 @@ static int _clog_ctr(char *uuid, uint64_t luid,
|
|||||||
lc->skip_bit_warning = region_count;
|
lc->skip_bit_warning = region_count;
|
||||||
lc->disk_fd = -1;
|
lc->disk_fd = -1;
|
||||||
lc->log_dev_failed = 0;
|
lc->log_dev_failed = 0;
|
||||||
if (!dm_strncpy(lc->uuid, uuid, DM_UUID_LEN)) {
|
if (!dm_strncpy_check(lc->uuid, uuid, DM_UUID_LEN)) {
|
||||||
LOG_ERROR("Cannot use too long UUID %s.", uuid);
|
LOG_ERROR("Cannot use too long UUID %s.", uuid);
|
||||||
r = -EINVAL;
|
r = -EINVAL;
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -641,7 +641,7 @@ static int _is_usable_uuid(const struct device *dev, const char *name, const cha
|
|||||||
|
|
||||||
/* Recognize some older reserved LVs just from the LV name (snapshot, pvmove...) */
|
/* Recognize some older reserved LVs just from the LV name (snapshot, pvmove...) */
|
||||||
vgname = vg_name;
|
vgname = vg_name;
|
||||||
if (!dm_strncpy(vg_name, name, sizeof(vg_name)) ||
|
if (!dm_strncpy_check(vg_name, name, sizeof(vg_name)) ||
|
||||||
!dm_split_lvm_name(NULL, NULL, &vgname, &lvname, &layer))
|
!dm_split_lvm_name(NULL, NULL, &vgname, &lvname, &layer))
|
||||||
return_0;
|
return_0;
|
||||||
|
|
||||||
|
@ -861,7 +861,7 @@ static int _insert_dir(const char *dir)
|
|||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
if (!dm_strncpy(path, dir, sizeof(path) - 1)) {
|
if (!dm_strncpy_check(path, dir, sizeof(path))) {
|
||||||
log_debug_devs("Dir path %s is too long", path);
|
log_debug_devs("Dir path %s is too long", path);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -876,7 +876,7 @@ static int _insert_dir(const char *dir)
|
|||||||
if (dirent[n]->d_name[0] == '.')
|
if (dirent[n]->d_name[0] == '.')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!dm_strncpy(path + len, dirent[n]->d_name, sizeof(path) - len)) {
|
if (!dm_strncpy_check(path + len, dirent[n]->d_name, sizeof(path) - len)) {
|
||||||
log_debug_devs("Path %s/%s is too long.", dir, dirent[n]->d_name);
|
log_debug_devs("Path %s/%s is too long.", dir, dirent[n]->d_name);
|
||||||
r = 0;
|
r = 0;
|
||||||
continue;
|
continue;
|
||||||
|
@ -278,7 +278,7 @@ int fs_mount_state_is_misnamed(struct cmd_context *cmd, struct logical_volume *l
|
|||||||
continue;
|
continue;
|
||||||
if (stme.st_dev != st_lv.st_rdev)
|
if (stme.st_dev != st_lv.st_rdev)
|
||||||
continue;
|
continue;
|
||||||
if (!dm_strncpy(mtab_mntpath, me->mnt_dir, sizeof(mtab_mntpath)))
|
if (!dm_strncpy_check(mtab_mntpath, me->mnt_dir, sizeof(mtab_mntpath)))
|
||||||
continue; /* Ignore too long unsupported paths */
|
continue; /* Ignore too long unsupported paths */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -837,18 +837,18 @@ static int _read_hint_file(struct cmd_context *cmd, struct dm_list *hints, int *
|
|||||||
vgname = split[3];
|
vgname = split[3];
|
||||||
|
|
||||||
if (name && !strncmp(name, "scan:", 5))
|
if (name && !strncmp(name, "scan:", 5))
|
||||||
if (!dm_strncpy(hint.name, name + 5, sizeof(hint.name)))
|
if (!dm_strncpy_check(hint.name, name + 5, sizeof(hint.name)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (pvid && !strncmp(pvid, "pvid:", 5))
|
if (pvid && !strncmp(pvid, "pvid:", 5))
|
||||||
if (!dm_strncpy(hint.pvid, pvid + 5, sizeof(hint.pvid)))
|
if (!dm_strncpy_check(hint.pvid, pvid + 5, sizeof(hint.pvid)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (devn && sscanf(devn, "devn:%d:%d", &major, &minor) == 2)
|
if (devn && sscanf(devn, "devn:%d:%d", &major, &minor) == 2)
|
||||||
hint.devt = makedev(major, minor);
|
hint.devt = makedev(major, minor);
|
||||||
|
|
||||||
if (vgname && (strlen(vgname) > 3) && (vgname[4] != '-'))
|
if (vgname && (strlen(vgname) > 3) && (vgname[4] != '-'))
|
||||||
if (!dm_strncpy(hint.vgname, vgname + 3, sizeof(hint.vgname)))
|
if (!dm_strncpy_check(hint.vgname, vgname + 3, sizeof(hint.vgname)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!(alloc_hint = zalloc(sizeof(struct hint)))) {
|
if (!(alloc_hint = zalloc(sizeof(struct hint)))) {
|
||||||
|
@ -77,7 +77,7 @@ int init_file_locking(struct locking_type *locking, struct cmd_context *cmd,
|
|||||||
|
|
||||||
/* Get lockfile directory from config file */
|
/* Get lockfile directory from config file */
|
||||||
locking_dir = find_config_tree_str(cmd, global_locking_dir_CFG, NULL);
|
locking_dir = find_config_tree_str(cmd, global_locking_dir_CFG, NULL);
|
||||||
if (!dm_strncpy(_lock_dir, locking_dir, sizeof(_lock_dir))) {
|
if (!dm_strncpy_check(_lock_dir, locking_dir, sizeof(_lock_dir))) {
|
||||||
log_error("Path for locking_dir %s is invalid.", locking_dir);
|
log_error("Path for locking_dir %s is invalid.", locking_dir);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,7 @@ int lock_vol(struct cmd_context *cmd, const char *vol, uint32_t flags, const str
|
|||||||
if (!_blocking_supported)
|
if (!_blocking_supported)
|
||||||
flags |= LCK_NONBLOCK;
|
flags |= LCK_NONBLOCK;
|
||||||
|
|
||||||
if (!dm_strncpy(resource, vol, sizeof(resource))) {
|
if (!dm_strncpy_check(resource, vol, sizeof(resource))) {
|
||||||
log_error(INTERNAL_ERROR "Resource name %s is too long.", vol);
|
log_error(INTERNAL_ERROR "Resource name %s is too long.", vol);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -887,7 +887,7 @@ int vg_remove_pool_metadata_spare(struct volume_group *vg)
|
|||||||
lv_set_visible(lv);
|
lv_set_visible(lv);
|
||||||
|
|
||||||
/* Cut off suffix _pmspare */
|
/* Cut off suffix _pmspare */
|
||||||
if (!dm_strncpy(new_name, lv->name, sizeof(new_name)) ||
|
if (!dm_strncpy_check(new_name, lv->name, sizeof(new_name)) ||
|
||||||
!(c = strchr(new_name, '_'))) {
|
!(c = strchr(new_name, '_'))) {
|
||||||
log_error(INTERNAL_ERROR "LV %s has no suffix for pool metadata spare.",
|
log_error(INTERNAL_ERROR "LV %s has no suffix for pool metadata spare.",
|
||||||
display_lvname(lv));
|
display_lvname(lv));
|
||||||
|
@ -146,7 +146,7 @@ static void _rename_detached_cvol(struct cmd_context *cmd, struct logical_volume
|
|||||||
* Failing to rename is not really a problem, so we intentionally
|
* Failing to rename is not really a problem, so we intentionally
|
||||||
* do not consider some things here as errors.
|
* do not consider some things here as errors.
|
||||||
*/
|
*/
|
||||||
if (!dm_strncpy(cvol_name, lv_fast->name, sizeof(cvol_name)) ||
|
if (!dm_strncpy_check(cvol_name, lv_fast->name, sizeof(cvol_name)) ||
|
||||||
!(suffix = strstr(cvol_name, "_cvol"))) {
|
!(suffix = strstr(cvol_name, "_cvol"))) {
|
||||||
log_debug("LV %s has no suffix for cachevol (skipping rename).",
|
log_debug("LV %s has no suffix for cachevol (skipping rename).",
|
||||||
display_lvname(lv_fast));
|
display_lvname(lv_fast));
|
||||||
|
@ -302,7 +302,7 @@ int drop_lvname_suffix(char *new_name, const char *name, const char *suffix)
|
|||||||
{
|
{
|
||||||
char *c;
|
char *c;
|
||||||
|
|
||||||
if (!dm_strncpy(new_name, name, NAME_LEN)) {
|
if (!dm_strncpy_check(new_name, name, NAME_LEN)) {
|
||||||
log_debug(INTERNAL_ERROR "Name is too long.");
|
log_debug(INTERNAL_ERROR "Name is too long.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ daemon_handle daemon_open(daemon_info i)
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dm_strncpy(sockaddr.sun_path, i.socket, sizeof(sockaddr.sun_path))) {
|
if (!dm_strncpy_check(sockaddr.sun_path, i.socket, sizeof(sockaddr.sun_path))) {
|
||||||
log_error("%s: Daemon socket path too long.", i.socket);
|
log_error("%s: Daemon socket path too long.", i.socket);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -249,7 +249,7 @@ static int _open_socket(daemon_state s)
|
|||||||
fprintf(stderr, "setting O_NONBLOCK on socket fd %d failed: %s\n", fd, strerror(errno));
|
fprintf(stderr, "setting O_NONBLOCK on socket fd %d failed: %s\n", fd, strerror(errno));
|
||||||
|
|
||||||
fprintf(stderr, "[D] creating %s\n", s.socket_path);
|
fprintf(stderr, "[D] creating %s\n", s.socket_path);
|
||||||
if (!dm_strncpy(sockaddr.sun_path, s.socket_path, sizeof(sockaddr.sun_path))) {
|
if (!dm_strncpy_check(sockaddr.sun_path, s.socket_path, sizeof(sockaddr.sun_path))) {
|
||||||
fprintf(stderr, "%s: daemon socket path too long.\n", s.socket_path);
|
fprintf(stderr, "%s: daemon socket path too long.\n", s.socket_path);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -6608,7 +6608,7 @@ static char *_parse_loop_device_name(const char *dev, const char *dev_dir)
|
|||||||
device[strlen(dev_dir)] != '/')
|
device[strlen(dev_dir)] != '/')
|
||||||
goto_bad;
|
goto_bad;
|
||||||
|
|
||||||
if (!dm_strncpy(buf, strrchr(device, '/') + 1, PATH_MAX))
|
if (!dm_strncpy_check(buf, strrchr(device, '/') + 1, PATH_MAX))
|
||||||
goto_bad;
|
goto_bad;
|
||||||
free(device);
|
free(device);
|
||||||
} else {
|
} else {
|
||||||
@ -6616,7 +6616,7 @@ static char *_parse_loop_device_name(const char *dev, const char *dev_dir)
|
|||||||
if (strncmp(dev, "loop", sizeof("loop") - 1))
|
if (strncmp(dev, "loop", sizeof("loop") - 1))
|
||||||
goto_bad;
|
goto_bad;
|
||||||
|
|
||||||
if (!dm_strncpy(buf, dev, PATH_MAX))
|
if (!dm_strncpy_check(buf, dev, PATH_MAX))
|
||||||
goto_bad;
|
goto_bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1916,7 +1916,7 @@ static char *_build_group_tag(struct dm_stats *dms, uint64_t group_id)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dm_strncpy(buf, DMS_GROUP_TAG, DMS_GROUP_TAG_LEN + 1))
|
if (!dm_strncpy_check(buf, DMS_GROUP_TAG, DMS_GROUP_TAG_LEN + 1))
|
||||||
goto_bad;
|
goto_bad;
|
||||||
|
|
||||||
buf += DMS_GROUP_TAG_LEN;
|
buf += DMS_GROUP_TAG_LEN;
|
||||||
|
@ -64,6 +64,9 @@ static int dm_strncpy(char *dest, const char *src, size_t n)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
static inline int dm_strncpy_check(char *dest, const char *src, size_t n) {
|
||||||
|
return dm_strncpy(dest, src, n);
|
||||||
|
}
|
||||||
|
|
||||||
static char *dm_pool_strdup(void *p, const char *str)
|
static char *dm_pool_strdup(void *p, const char *str)
|
||||||
{
|
{
|
||||||
@ -347,7 +350,7 @@ static int _val_str_to_num(char *str)
|
|||||||
|
|
||||||
/* compare the name before any suffix like _new or _<lvtype> */
|
/* compare the name before any suffix like _new or _<lvtype> */
|
||||||
|
|
||||||
if (!dm_strncpy(name, str, sizeof(name)))
|
if (!dm_strncpy_check(name, str, sizeof(name)))
|
||||||
return 0; /* Buffer is too short */
|
return 0; /* Buffer is too short */
|
||||||
|
|
||||||
if ((new = strchr(name, '_')))
|
if ((new = strchr(name, '_')))
|
||||||
@ -374,7 +377,7 @@ static int _opt_str_to_num(struct command *cmd, const char *str)
|
|||||||
int i;
|
int i;
|
||||||
int first = 0, last = ARG_COUNT - 1, middle;
|
int first = 0, last = ARG_COUNT - 1, middle;
|
||||||
|
|
||||||
if (!dm_strncpy(long_name, str, sizeof(long_name)))
|
if (!dm_strncpy_check(long_name, str, sizeof(long_name)))
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
if ((p = strstr(long_name, "_long")))
|
if ((p = strstr(long_name, "_long")))
|
||||||
|
@ -155,7 +155,7 @@ static int _remove_sibling_pvs_from_trim_list(struct logical_volume *lv,
|
|||||||
|
|
||||||
dm_list_init(&untrim_list);
|
dm_list_init(&untrim_list);
|
||||||
|
|
||||||
if (!dm_strncpy(sublv_name, lv_name, sizeof(sublv_name))) {
|
if (!dm_strncpy_check(sublv_name, lv_name, sizeof(sublv_name))) {
|
||||||
log_error(INTERNAL_ERROR "LV name %s is too long.", lv_name);
|
log_error(INTERNAL_ERROR "LV name %s is too long.", lv_name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -176,7 +176,7 @@ static int _remove_sibling_pvs_from_trim_list(struct logical_volume *lv,
|
|||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
/* Copy idx to local buffer */
|
/* Copy idx to local buffer */
|
||||||
if (!dm_strncpy(idx_buf, idx, sizeof(idx_buf))) {
|
if (!dm_strncpy_check(idx_buf, idx, sizeof(idx_buf))) {
|
||||||
log_error(INTERNAL_ERROR "Unexpected LV index %s.", idx);
|
log_error(INTERNAL_ERROR "Unexpected LV index %s.", idx);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1059,7 +1059,7 @@ static int _set_report_prefix_and_name(struct report_args *args,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dm_strncpy(single_args->report_prefix, report_prefix, sizeof(single_args->report_prefix))) {
|
if (!dm_strncpy_check(single_args->report_prefix, report_prefix, sizeof(single_args->report_prefix))) {
|
||||||
log_error("_set_report_prefix_and_name: dm_strncpy failed");
|
log_error("_set_report_prefix_and_name: dm_strncpy failed");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ static int _check_all_dm_devices(const char *vg_name, unsigned *found)
|
|||||||
do {
|
do {
|
||||||
/* TODO: Do we want to validate UUID LVM- prefix as well ? */
|
/* TODO: Do we want to validate UUID LVM- prefix as well ? */
|
||||||
names = (struct dm_names *)((char *) names + next);
|
names = (struct dm_names *)((char *) names + next);
|
||||||
if (!dm_strncpy(vgname_buf, names->name, sizeof(vgname_buf))) {
|
if (!dm_strncpy_check(vgname_buf, names->name, sizeof(vgname_buf))) {
|
||||||
r = 0;
|
r = 0;
|
||||||
goto_out;
|
goto_out;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user