criu: convert to strnprintf()

parent e6aeee83
...@@ -83,8 +83,8 @@ static int load_tty_major_minor(char *directory, char *output, int len) ...@@ -83,8 +83,8 @@ static int load_tty_major_minor(char *directory, char *output, int len)
char path[PATH_MAX]; char path[PATH_MAX];
ssize_t ret; ssize_t ret;
ret = snprintf(path, sizeof(path), "%s/tty.info", directory); ret = strnprintf(path, sizeof(path), "%s/tty.info", directory);
if (ret < 0 || (size_t)ret >= sizeof(path)) if (ret < 0)
return ret_errno(EIO); return ret_errno(EIO);
ret = lxc_read_from_file(path, output, len); ret = lxc_read_from_file(path, output, len);
...@@ -249,8 +249,8 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf, ...@@ -249,8 +249,8 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf,
static_args += 2 * lxc_list_len(&opts->c->lxc_conf->mount_list); static_args += 2 * lxc_list_len(&opts->c->lxc_conf->mount_list);
ret = snprintf(log, PATH_MAX, "%s/%s.log", opts->user->directory, opts->action); ret = strnprintf(log, sizeof(log), "%s/%s.log", opts->user->directory, opts->action);
if (ret < 0 || ret >= PATH_MAX) if (ret < 0)
return ret_errno(EIO); return ret_errno(EIO);
args = zalloc(sizeof(struct criu_exec_args) + (static_args * sizeof(char **))); args = zalloc(sizeof(struct criu_exec_args) + (static_args * sizeof(char **)));
...@@ -367,10 +367,10 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf, ...@@ -367,10 +367,10 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf,
continue; continue;
if (strcmp(opts->action, "dump") == 0) if (strcmp(opts->action, "dump") == 0)
ret = snprintf(arg, sizeof(arg), "/%s:%s", mntent.mnt_dir, mntent.mnt_dir); ret = strnprintf(arg, sizeof(arg), "/%s:%s", mntent.mnt_dir, mntent.mnt_dir);
else else
ret = snprintf(arg, sizeof(arg), "%s:%s", mntent.mnt_dir, mntent.mnt_fsname); ret = strnprintf(arg, sizeof(arg), "%s:%s", mntent.mnt_dir, mntent.mnt_fsname);
if (ret < 0 || ret >= sizeof(arg)) if (ret < 0)
return log_error_errno(-EIO, EIO, "Failed to create mount entry"); return log_error_errno(-EIO, EIO, "Failed to create mount entry");
DECLARE_ARG("--ext-mount-map"); DECLARE_ARG("--ext-mount-map");
...@@ -386,8 +386,8 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf, ...@@ -386,8 +386,8 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf,
if (init_pid < 0) if (init_pid < 0)
return log_error_errno(-ESRCH, ESRCH, "Failed to retrieve init pid of container"); return log_error_errno(-ESRCH, ESRCH, "Failed to retrieve init pid of container");
ret = snprintf(init_pid_str, sizeof(init_pid_str), "%d", init_pid); ret = strnprintf(init_pid_str, sizeof(init_pid_str), "%d", init_pid);
if (ret < 0 || (size_t)ret >= sizeof(init_pid_str)) if (ret < 0)
return log_error_errno(-EIO, EIO, "Failed to create entry for init pid of container"); return log_error_errno(-EIO, EIO, "Failed to create entry for init pid of container");
DECLARE_ARG("-t"); DECLARE_ARG("-t");
...@@ -400,10 +400,10 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf, ...@@ -400,10 +400,10 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf,
return log_error_errno(-ENOENT, ENOENT, "Failed getting freezer path"); return log_error_errno(-ENOENT, ENOENT, "Failed getting freezer path");
if (pure_unified_layout(cgroup_ops)) if (pure_unified_layout(cgroup_ops))
ret = snprintf(log, sizeof(log), "/sys/fs/cgroup/%s", freezer_relative); ret = strnprintf(log, sizeof(log), "/sys/fs/cgroup/%s", freezer_relative);
else else
ret = snprintf(log, sizeof(log), "/sys/fs/cgroup/freezer/%s", freezer_relative); ret = strnprintf(log, sizeof(log), "/sys/fs/cgroup/freezer/%s", freezer_relative);
if (ret < 0 || ret >= sizeof(log)) if (ret < 0)
return log_error_errno(-EIO, EIO, "Failed to freezer cgroup entry"); return log_error_errno(-EIO, EIO, "Failed to freezer cgroup entry");
if (!opts->user->disable_skip_in_flight && if (!opts->user->disable_skip_in_flight &&
...@@ -464,15 +464,15 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf, ...@@ -464,15 +464,15 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf,
if (opts->console_fd < 0) if (opts->console_fd < 0)
return log_error_errno(-EINVAL, EINVAL, "lxc.console.path configured on source host but not target"); return log_error_errno(-EINVAL, EINVAL, "lxc.console.path configured on source host but not target");
ret = snprintf(buf, sizeof(buf), "fd[%d]:%s", opts->console_fd, ttys); ret = strnprintf(buf, sizeof(buf), "fd[%d]:%s", opts->console_fd, ttys);
if (ret < 0 || ret >= sizeof(buf)) if (ret < 0)
return log_error_errno(-EIO, EIO, "Failed to create console entry"); return log_error_errno(-EIO, EIO, "Failed to create console entry");
DECLARE_ARG("--inherit-fd"); DECLARE_ARG("--inherit-fd");
DECLARE_ARG(buf); DECLARE_ARG(buf);
} }
if (opts->console_name) { if (opts->console_name) {
if (snprintf(buf, sizeof(buf), "console:%s", opts->console_name) < 0) if (strnprintf(buf, sizeof(buf), "console:%s", opts->console_name) < 0)
return log_error_errno(-EIO, EIO, "Failed to create console entry"); return log_error_errno(-EIO, EIO, "Failed to create console entry");
DECLARE_ARG("--ext-mount-map"); DECLARE_ARG("--ext-mount-map");
...@@ -482,10 +482,10 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf, ...@@ -482,10 +482,10 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf,
if (lxc_conf->lsm_aa_profile || lxc_conf->lsm_se_context) { if (lxc_conf->lsm_aa_profile || lxc_conf->lsm_se_context) {
if (lxc_conf->lsm_aa_profile) if (lxc_conf->lsm_aa_profile)
ret = snprintf(buf, sizeof(buf), "apparmor:%s", lxc_conf->lsm_aa_profile); ret = strnprintf(buf, sizeof(buf), "apparmor:%s", lxc_conf->lsm_aa_profile);
else else
ret = snprintf(buf, sizeof(buf), "selinux:%s", lxc_conf->lsm_se_context); ret = strnprintf(buf, sizeof(buf), "selinux:%s", lxc_conf->lsm_se_context);
if (ret < 0 || ret >= sizeof(buf)) if (ret < 0)
return log_error_errno(-EIO, EIO, "Failed to create lsm entry"); return log_error_errno(-EIO, EIO, "Failed to create lsm entry");
DECLARE_ARG("--lsm-profile"); DECLARE_ARG("--lsm-profile");
...@@ -513,8 +513,8 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf, ...@@ -513,8 +513,8 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf,
if (retlen >= sizeof(eth)) if (retlen >= sizeof(eth))
return log_error_errno(-E2BIG, E2BIG, "Failed to append veth device name"); return log_error_errno(-E2BIG, E2BIG, "Failed to append veth device name");
} else { } else {
ret = snprintf(eth, sizeof(eth), "eth%d", netnr); ret = strnprintf(eth, sizeof(eth), "eth%d", netnr);
if (ret < 0 || ret >= sizeof(eth)) if (ret < 0)
return log_error_errno(-E2BIG, E2BIG, "Failed to append veth device name"); return log_error_errno(-E2BIG, E2BIG, "Failed to append veth device name");
} }
...@@ -526,16 +526,16 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf, ...@@ -526,16 +526,16 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf,
if (n->link[0] != '\0') { if (n->link[0] != '\0') {
if (external_not_veth) if (external_not_veth)
ret = snprintf(buf, sizeof(buf), "veth[%s]:%s@%s", eth, veth, n->link); ret = strnprintf(buf, sizeof(buf), "veth[%s]:%s@%s", eth, veth, n->link);
else else
ret = snprintf(buf, sizeof(buf), "%s=%s@%s", eth, veth, n->link); ret = strnprintf(buf, sizeof(buf), "%s=%s@%s", eth, veth, n->link);
} else { } else {
if (external_not_veth) if (external_not_veth)
ret = snprintf(buf, sizeof(buf), "veth[%s]:%s", eth, veth); ret = strnprintf(buf, sizeof(buf), "veth[%s]:%s", eth, veth);
else else
ret = snprintf(buf, sizeof(buf), "%s=%s", eth, veth); ret = strnprintf(buf, sizeof(buf), "%s=%s", eth, veth);
} }
if (ret < 0 || ret >= sizeof(buf)) if (ret < 0)
return log_error_errno(-EIO, EIO, "Failed to append veth device name"); return log_error_errno(-EIO, EIO, "Failed to append veth device name");
TRACE("Added veth device entry %s", buf); TRACE("Added veth device entry %s", buf);
...@@ -544,8 +544,8 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf, ...@@ -544,8 +544,8 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf,
if (n->link[0] == '\0') if (n->link[0] == '\0')
return log_error_errno(-EINVAL, EINVAL, "Failed to find host interface for macvlan %s", n->name); return log_error_errno(-EINVAL, EINVAL, "Failed to find host interface for macvlan %s", n->name);
ret = snprintf(buf, sizeof(buf), "macvlan[%s]:%s", eth, n->link); ret = strnprintf(buf, sizeof(buf), "macvlan[%s]:%s", eth, n->link);
if (ret < 0 || ret >= sizeof(buf)) if (ret < 0)
return log_error_errno(-EIO, EIO, "Failed to add macvlan entry"); return log_error_errno(-EIO, EIO, "Failed to add macvlan entry");
TRACE("Added macvlan device entry %s", buf); TRACE("Added macvlan device entry %s", buf);
...@@ -574,8 +574,8 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf, ...@@ -574,8 +574,8 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf,
if (lxc_log_trace()) { if (lxc_log_trace()) {
buf[0] = 0; buf[0] = 0;
for (int i = 0, pos = 0; i < args->argc && args->argv[i]; i++) { for (int i = 0, pos = 0; i < args->argc && args->argv[i]; i++) {
ret = snprintf(buf + pos, sizeof(buf) - pos, "%s ", args->argv[i]); ret = strnprintf(buf + pos, sizeof(buf) - pos, "%s ", args->argv[i]);
if (ret < 0 || ret >= sizeof(buf) - pos) if (ret < 0)
return log_error_errno(-EIO, EIO, "Failed to reorder entries"); return log_error_errno(-EIO, EIO, "Failed to reorder entries");
else else
pos += ret; pos += ret;
...@@ -857,8 +857,8 @@ static bool restore_net_info(struct lxc_container *c) ...@@ -857,8 +857,8 @@ static bool restore_net_info(struct lxc_container *c)
if (netdev->type != LXC_NET_VETH) if (netdev->type != LXC_NET_VETH)
continue; continue;
ret = snprintf(template, sizeof(template), "vethXXXXXX"); ret = strnprintf(template, sizeof(template), "vethXXXXXX");
if (ret < 0 || ret >= sizeof(template)) if (ret < 0)
goto out_unlock; goto out_unlock;
if (netdev->priv.veth_attr.pair[0] == '\0' && if (netdev->priv.veth_attr.pair[0] == '\0' &&
...@@ -1052,9 +1052,9 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_ ...@@ -1052,9 +1052,9 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_
ERROR("criu process exited %d, output:\n%s", WEXITSTATUS(status), buf); ERROR("criu process exited %d, output:\n%s", WEXITSTATUS(status), buf);
goto out_fini_handler; goto out_fini_handler;
} else { } else {
ret = snprintf(buf, sizeof(buf), "/proc/self/task/%lu/children", (unsigned long)syscall(__NR_gettid)); ret = strnprintf(buf, sizeof(buf), "/proc/self/task/%lu/children", (unsigned long)syscall(__NR_gettid));
if (ret < 0 || ret >= sizeof(buf)) { if (ret < 0) {
ERROR("snprintf'd too many characters: %d", ret); ERROR("strnprintf'd too many characters: %d", ret);
goto out_fini_handler; goto out_fini_handler;
} }
...@@ -1097,8 +1097,8 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_ ...@@ -1097,8 +1097,8 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_
* fail because it's just a beauty thing. We just * fail because it's just a beauty thing. We just
* assign the return here to silence potential. * assign the return here to silence potential.
*/ */
ret = snprintf(title, sizeof(title), "[lxc monitor] %s %s", c->config_path, c->name); ret = strnprintf(title, sizeof(title), "[lxc monitor] %s %s", c->config_path, c->name);
if (ret < 0 || (size_t)ret >= sizeof(title)) if (ret < 0)
INFO("Setting truncated process name"); INFO("Setting truncated process name");
ret = setproctitle(title); ret = setproctitle(title);
...@@ -1149,9 +1149,9 @@ static int save_tty_major_minor(char *directory, struct lxc_container *c, char * ...@@ -1149,9 +1149,9 @@ static int save_tty_major_minor(char *directory, struct lxc_container *c, char *
return 0; return 0;
} }
ret = snprintf(path, sizeof(path), "/proc/%d/root/dev/console", c->init_pid(c)); ret = strnprintf(path, sizeof(path), "/proc/%d/root/dev/console", c->init_pid(c));
if (ret < 0 || ret >= sizeof(path)) { if (ret < 0) {
ERROR("snprintf'd too many characters: %d", ret); ERROR("strnprintf'd too many characters: %d", ret);
return -1; return -1;
} }
...@@ -1161,17 +1161,17 @@ static int save_tty_major_minor(char *directory, struct lxc_container *c, char * ...@@ -1161,17 +1161,17 @@ static int save_tty_major_minor(char *directory, struct lxc_container *c, char *
return -1; return -1;
} }
ret = snprintf(path, sizeof(path), "%s/tty.info", directory); ret = strnprintf(path, sizeof(path), "%s/tty.info", directory);
if (ret < 0 || ret >= sizeof(path)) { if (ret < 0) {
ERROR("snprintf'd too many characters: %d", ret); ERROR("strnprintf'd too many characters: %d", ret);
return -1; return -1;
} }
ret = snprintf(tty_id, len, "tty[%llx:%llx]", ret = strnprintf(tty_id, len, "tty[%llx:%llx]",
(long long unsigned) sb.st_rdev, (long long unsigned) sb.st_rdev,
(long long unsigned) sb.st_dev); (long long unsigned) sb.st_dev);
if (ret < 0 || ret >= sizeof(path)) { if (ret < 0) {
ERROR("snprintf'd too many characters: %d", ret); ERROR("strnprintf'd too many characters: %d", ret);
return -1; return -1;
} }
...@@ -1313,8 +1313,8 @@ bool __criu_dump(struct lxc_container *c, struct migrate_opts *opts) ...@@ -1313,8 +1313,8 @@ bool __criu_dump(struct lxc_container *c, struct migrate_opts *opts)
char path[PATH_MAX]; char path[PATH_MAX];
int ret; int ret;
ret = snprintf(path, sizeof(path), "%s/inventory.img", opts->directory); ret = strnprintf(path, sizeof(path), "%s/inventory.img", opts->directory);
if (ret < 0 || ret >= sizeof(path)) if (ret < 0)
return false; return false;
if (access(path, F_OK) == 0) { if (access(path, F_OK) == 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment