diff --git a/daemons/cmirrord/functions.c b/daemons/cmirrord/functions.c index 834cb0b3a..044545925 100644 --- a/daemons/cmirrord/functions.c +++ b/daemons/cmirrord/functions.c @@ -452,7 +452,7 @@ static int _clog_ctr(char *uuid, uint64_t luid, lc->skip_bit_warning = region_count; lc->disk_fd = -1; lc->log_dev_failed = 0; - if (!dm_strncpy(lc->uuid, uuid, DM_UUID_LEN)) { + if (!_dm_strncpy(lc->uuid, uuid, DM_UUID_LEN)) { LOG_ERROR("Cannot use too long UUID %s.", uuid); r = -EINVAL; goto fail; diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c index c351730eb..073152133 100644 --- a/lib/activate/dev_manager.c +++ b/lib/activate/dev_manager.c @@ -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...) */ vgname = vg_name; - if (!dm_strncpy(vg_name, name, sizeof(vg_name)) || + if (!_dm_strncpy(vg_name, name, sizeof(vg_name)) || !dm_split_lvm_name(NULL, NULL, &vgname, &lvname, &layer)) return_0; diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c index 5d96db057..fadcaca34 100644 --- a/lib/device/dev-cache.c +++ b/lib/device/dev-cache.c @@ -861,7 +861,7 @@ static int _insert_dir(const char *dir) char path[PATH_MAX]; size_t len; - if (!dm_strncpy(path, dir, sizeof(path) - 1)) { + if (!_dm_strncpy(path, dir, sizeof(path))) { log_debug_devs("Dir path %s is too long", path); return 0; } @@ -876,7 +876,7 @@ static int _insert_dir(const char *dir) if (dirent[n]->d_name[0] == '.') continue; - if (!dm_strncpy(path + len, dirent[n]->d_name, sizeof(path) - len)) { + if (!_dm_strncpy(path + len, dirent[n]->d_name, sizeof(path) - len)) { log_debug_devs("Path %s/%s is too long.", dir, dirent[n]->d_name); r = 0; continue; diff --git a/lib/device/filesystem.c b/lib/device/filesystem.c index 78dc99b91..48ca0204a 100644 --- a/lib/device/filesystem.c +++ b/lib/device/filesystem.c @@ -278,7 +278,7 @@ int fs_mount_state_is_misnamed(struct cmd_context *cmd, struct logical_volume *l continue; if (stme.st_dev != st_lv.st_rdev) continue; - if (!dm_strncpy(mtab_mntpath, me->mnt_dir, sizeof(mtab_mntpath))) + if (!_dm_strncpy(mtab_mntpath, me->mnt_dir, sizeof(mtab_mntpath))) continue; /* Ignore too long unsupported paths */ break; } diff --git a/lib/label/hints.c b/lib/label/hints.c index c26410603..5ea30e2ea 100644 --- a/lib/label/hints.c +++ b/lib/label/hints.c @@ -837,18 +837,18 @@ static int _read_hint_file(struct cmd_context *cmd, struct dm_list *hints, int * vgname = split[3]; if (name && !strncmp(name, "scan:", 5)) - if (!dm_strncpy(hint.name, name + 5, sizeof(hint.name))) + if (!_dm_strncpy(hint.name, name + 5, sizeof(hint.name))) continue; if (pvid && !strncmp(pvid, "pvid:", 5)) - if (!dm_strncpy(hint.pvid, pvid + 5, sizeof(hint.pvid))) + if (!_dm_strncpy(hint.pvid, pvid + 5, sizeof(hint.pvid))) continue; if (devn && sscanf(devn, "devn:%d:%d", &major, &minor) == 2) hint.devt = makedev(major, minor); if (vgname && (strlen(vgname) > 3) && (vgname[4] != '-')) - if (!dm_strncpy(hint.vgname, vgname + 3, sizeof(hint.vgname))) + if (!_dm_strncpy(hint.vgname, vgname + 3, sizeof(hint.vgname))) continue; if (!(alloc_hint = zalloc(sizeof(struct hint)))) { diff --git a/lib/locking/file_locking.c b/lib/locking/file_locking.c index 9dfa06cf5..f697e98ee 100644 --- a/lib/locking/file_locking.c +++ b/lib/locking/file_locking.c @@ -77,7 +77,7 @@ int init_file_locking(struct locking_type *locking, struct cmd_context *cmd, /* Get lockfile directory from config file */ 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(_lock_dir, locking_dir, sizeof(_lock_dir))) { log_error("Path for locking_dir %s is invalid.", locking_dir); return 0; } diff --git a/lib/locking/locking.c b/lib/locking/locking.c index a8153a693..8ce979826 100644 --- a/lib/locking/locking.c +++ b/lib/locking/locking.c @@ -206,7 +206,7 @@ int lock_vol(struct cmd_context *cmd, const char *vol, uint32_t flags, const str if (!_blocking_supported) flags |= LCK_NONBLOCK; - if (!dm_strncpy(resource, vol, sizeof(resource))) { + if (!_dm_strncpy(resource, vol, sizeof(resource))) { log_error(INTERNAL_ERROR "Resource name %s is too long.", vol); return 0; } diff --git a/lib/metadata/pool_manip.c b/lib/metadata/pool_manip.c index 105656bca..9e54e7281 100644 --- a/lib/metadata/pool_manip.c +++ b/lib/metadata/pool_manip.c @@ -887,7 +887,7 @@ int vg_remove_pool_metadata_spare(struct volume_group *vg) lv_set_visible(lv); /* Cut off suffix _pmspare */ - if (!dm_strncpy(new_name, lv->name, sizeof(new_name)) || + if (!_dm_strncpy(new_name, lv->name, sizeof(new_name)) || !(c = strchr(new_name, '_'))) { log_error(INTERNAL_ERROR "LV %s has no suffix for pool metadata spare.", display_lvname(lv)); diff --git a/lib/metadata/writecache_manip.c b/lib/metadata/writecache_manip.c index 21b7940fb..208913c2e 100644 --- a/lib/metadata/writecache_manip.c +++ b/lib/metadata/writecache_manip.c @@ -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 * do not consider some things here as errors. */ - if (!dm_strncpy(cvol_name, lv_fast->name, sizeof(cvol_name)) || + if (!_dm_strncpy(cvol_name, lv_fast->name, sizeof(cvol_name)) || !(suffix = strstr(cvol_name, "_cvol"))) { log_debug("LV %s has no suffix for cachevol (skipping rename).", display_lvname(lv_fast)); diff --git a/lib/misc/lvm-string.c b/lib/misc/lvm-string.c index 959a6a16e..0f4c80f82 100644 --- a/lib/misc/lvm-string.c +++ b/lib/misc/lvm-string.c @@ -302,7 +302,7 @@ int drop_lvname_suffix(char *new_name, const char *name, const char *suffix) { char *c; - if (!dm_strncpy(new_name, name, NAME_LEN)) { + if (!_dm_strncpy(new_name, name, NAME_LEN)) { log_debug(INTERNAL_ERROR "Name is too long."); return 0; } diff --git a/libdaemon/client/daemon-client.c b/libdaemon/client/daemon-client.c index 804968632..bb8be30e3 100644 --- a/libdaemon/client/daemon-client.c +++ b/libdaemon/client/daemon-client.c @@ -36,7 +36,7 @@ daemon_handle daemon_open(daemon_info i) goto error; } - if (!dm_strncpy(sockaddr.sun_path, i.socket, sizeof(sockaddr.sun_path))) { + if (!_dm_strncpy(sockaddr.sun_path, i.socket, sizeof(sockaddr.sun_path))) { log_error("%s: Daemon socket path too long.", i.socket); goto error; } diff --git a/libdaemon/server/daemon-server.c b/libdaemon/server/daemon-server.c index dde7f5982..38d8b4b60 100644 --- a/libdaemon/server/daemon-server.c +++ b/libdaemon/server/daemon-server.c @@ -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, "[D] creating %s\n", s.socket_path); - if (!dm_strncpy(sockaddr.sun_path, s.socket_path, sizeof(sockaddr.sun_path))) { + if (!_dm_strncpy(sockaddr.sun_path, s.socket_path, sizeof(sockaddr.sun_path))) { fprintf(stderr, "%s: daemon socket path too long.\n", s.socket_path); goto error; } diff --git a/libdm/dm-tools/dmsetup.c b/libdm/dm-tools/dmsetup.c index d0e016607..8769f42ec 100644 --- a/libdm/dm-tools/dmsetup.c +++ b/libdm/dm-tools/dmsetup.c @@ -6608,7 +6608,7 @@ static char *_parse_loop_device_name(const char *dev, const char *dev_dir) device[strlen(dev_dir)] != '/') goto_bad; - if (!dm_strncpy(buf, strrchr(device, '/') + 1, PATH_MAX)) + if (!_dm_strncpy(buf, strrchr(device, '/') + 1, PATH_MAX)) goto_bad; free(device); } 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)) goto_bad; - if (!dm_strncpy(buf, dev, PATH_MAX)) + if (!_dm_strncpy(buf, dev, PATH_MAX)) goto_bad; } diff --git a/libdm/libdm-stats.c b/libdm/libdm-stats.c index cccccac8e..121c2ce4a 100644 --- a/libdm/libdm-stats.c +++ b/libdm/libdm-stats.c @@ -1916,7 +1916,7 @@ static char *_build_group_tag(struct dm_stats *dms, uint64_t group_id) return NULL; } - if (!dm_strncpy(buf, DMS_GROUP_TAG, DMS_GROUP_TAG_LEN + 1)) + if (!_dm_strncpy(buf, DMS_GROUP_TAG, DMS_GROUP_TAG_LEN + 1)) goto_bad; buf += DMS_GROUP_TAG_LEN; diff --git a/tools/command.c b/tools/command.c index 91c33b408..37ced6443 100644 --- a/tools/command.c +++ b/tools/command.c @@ -64,6 +64,9 @@ static int dm_strncpy(char *dest, const char *src, size_t n) return 0; } +static inline int _dm_strncpy(char *dest, const char *src, size_t n) { + return dm_strncpy(dest, src, n); +} 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 _ */ - if (!dm_strncpy(name, str, sizeof(name))) + if (!_dm_strncpy(name, str, sizeof(name))) return 0; /* Buffer is too short */ if ((new = strchr(name, '_'))) @@ -374,7 +377,7 @@ static int _opt_str_to_num(struct command *cmd, const char *str) int i; int first = 0, last = ARG_COUNT - 1, middle; - if (!dm_strncpy(long_name, str, sizeof(long_name))) + if (!_dm_strncpy(long_name, str, sizeof(long_name))) goto err; if ((p = strstr(long_name, "_long"))) diff --git a/tools/pvmove.c b/tools/pvmove.c index 4113dcbc3..dd68e33d1 100644 --- a/tools/pvmove.c +++ b/tools/pvmove.c @@ -155,7 +155,7 @@ static int _remove_sibling_pvs_from_trim_list(struct logical_volume *lv, dm_list_init(&untrim_list); - if (!dm_strncpy(sublv_name, lv_name, sizeof(sublv_name))) { + if (!_dm_strncpy(sublv_name, lv_name, sizeof(sublv_name))) { log_error(INTERNAL_ERROR "LV name %s is too long.", lv_name); return 0; } @@ -176,7 +176,7 @@ static int _remove_sibling_pvs_from_trim_list(struct logical_volume *lv, idx++; /* Copy idx to local buffer */ - if (!dm_strncpy(idx_buf, idx, sizeof(idx_buf))) { + if (!_dm_strncpy(idx_buf, idx, sizeof(idx_buf))) { log_error(INTERNAL_ERROR "Unexpected LV index %s.", idx); return 0; } diff --git a/tools/reporter.c b/tools/reporter.c index a28780298..764dfdecc 100644 --- a/tools/reporter.c +++ b/tools/reporter.c @@ -1059,7 +1059,7 @@ static int _set_report_prefix_and_name(struct report_args *args, return 0; } - if (!dm_strncpy(single_args->report_prefix, report_prefix, sizeof(single_args->report_prefix))) { + if (!_dm_strncpy(single_args->report_prefix, report_prefix, sizeof(single_args->report_prefix))) { log_error("_set_report_prefix_and_name: dm_strncpy failed"); return 0; } diff --git a/tools/vgcfgrestore.c b/tools/vgcfgrestore.c index 9fcba89d4..1b51299ea 100644 --- a/tools/vgcfgrestore.c +++ b/tools/vgcfgrestore.c @@ -52,7 +52,7 @@ static int _check_all_dm_devices(const char *vg_name, unsigned *found) do { /* TODO: Do we want to validate UUID LVM- prefix as well ? */ names = (struct dm_names *)((char *) names + next); - if (!dm_strncpy(vgname_buf, names->name, sizeof(vgname_buf))) { + if (!_dm_strncpy(vgname_buf, names->name, sizeof(vgname_buf))) { r = 0; goto_out; }