static int add_shmount_to_list(struct lxc_conf *conf) {
char new_mount[MAXPATHLEN];
- size_t len_mount;
/* Offset for the leading '/' since the path_cont
* is absolute inside the container */
int ret = -1, offset = 1;
- /* +1 for the separating whitespace */
- len_mount = strlen(conf->shmount.path_host) + 1
- + strlen(conf->shmount.path_cont) - offset
- + sizeof(" none bind,create=dir 0 0") - 1;
-
- ret = snprintf(new_mount, len_mount + 1, "%s %s none bind,create=dir 0 0",
+ ret = snprintf(new_mount, sizeof(new_mount), "%s %s none bind,create=dir 0 0",
conf->shmount.path_host, conf->shmount.path_cont + offset);
- if (ret < 0 || (size_t)ret >= len_mount + 1)
+ if (ret < 0 || (size_t)ret >= sizeof(new_mount))
return -1;
ret = add_elem_to_mount_list(new_mount, conf);
struct lxc_mount *mnt)
{
char *suff, *sret;
- size_t len;
char template[MAXPATHLEN], path[MAXPATHLEN];
pid_t pid, init_pid;
struct stat sb;
ERROR("Host path to shared mountpoint must be specified in the config\n");
return -EINVAL;
}
- len = strlen(c->lxc_conf->shmount.path_host) + sizeof("/.lxcmount_XXXXXX") - 1;
- ret = snprintf(template, len + 1, "%s/.lxcmount_XXXXXX", c->lxc_conf->shmount.path_host);
- if (ret < 0 || (size_t)ret >= len + 1) {
+ ret = snprintf(template, sizeof(template), "%s/.lxcmount_XXXXXX", c->lxc_conf->shmount.path_host);
+ if (ret < 0 || (size_t)ret >= sizeof(template)) {
SYSERROR("Error writing shmounts tempdir name");
goto out;
}
if (!suff)
_exit(EXIT_FAILURE);
- len = strlen(c->lxc_conf->shmount.path_cont) + sizeof("/.lxcmount_XXXXXX") - 1;
- ret = snprintf(path, len + 1, "%s%s", c->lxc_conf->shmount.path_cont, suff);
- if (ret < 0 || (size_t)ret >= len + 1) {
+ ret = snprintf(path, sizeof(path), "%s%s", c->lxc_conf->shmount.path_cont, suff);
+ if (ret < 0 || (size_t)ret >= sizeof(path)) {
SYSERROR("Error writing container mountpoint name");
_exit(EXIT_FAILURE);
}