Skip to content

Commit

Permalink
secure coding: strcpy => strlcpy
Browse files Browse the repository at this point in the history
Signed-off-by: Donghwa Jeong <dh48.jeong@samsung.com>
  • Loading branch information
2xsec authored and Christian Brauner committed Jun 22, 2018
1 parent e9674af commit 604f376
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/lxc/criu.c
Expand Up @@ -923,7 +923,7 @@ static bool restore_net_info(struct lxc_container *c)
if (!lxc_mkifname(template))
goto out_unlock;

strcpy(netdev->priv.veth_attr.veth1, template);
(void)strlcpy(netdev->priv.veth_attr.veth1, template, IFNAMSIZ);
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/lxc/lxccontainer.c
Expand Up @@ -1192,7 +1192,8 @@ static int do_create_container_dir(const char *path, struct lxc_conf *conf)

len = strlen(path);
p = alloca(len + 1);
strcpy(p, path);
(void)strlcpy(p, path, len + 1);

if (!lxc_list_empty(&conf->id_map)) {
ret = chown_mapped_root(p, conf);
if (ret < 0)
Expand Down Expand Up @@ -4777,6 +4778,7 @@ static int lxcapi_attach_run_waitl(struct lxc_container *c, lxc_attach_options_t
struct lxc_container *lxc_container_new(const char *name, const char *configpath)
{
struct lxc_container *c;
size_t len;

if (!name)
return NULL;
Expand All @@ -4799,12 +4801,14 @@ struct lxc_container *lxc_container_new(const char *name, const char *configpath
}

remove_trailing_slashes(c->config_path);
c->name = malloc(strlen(name)+1);

len = strlen(name);
c->name = malloc(len + 1);
if (!c->name) {
fprintf(stderr, "Failed to allocate memory for %s\n", name);
goto err;
}
strcpy(c->name, name);
(void)strlcpy(c->name, name, len + 1);

c->numthreads = 1;
c->slock = lxc_newlock(c->config_path, name);
Expand Down
4 changes: 3 additions & 1 deletion src/lxc/start.c
Expand Up @@ -110,9 +110,11 @@ static void print_top_failing_dir(const char *path)

len = strlen(path);
copy = alloca(len + 1);
strcpy(copy, path);
(void)strlcpy(copy, path, len + 1);

p = copy;
e = copy + len;

while (p < e) {
while (p < e && *p == '/')
p++;
Expand Down
13 changes: 8 additions & 5 deletions src/lxc/storage/btrfs.c
Expand Up @@ -88,8 +88,8 @@ char *get_btrfs_subvol_path(int fd, u64 dir_id, u64 objid, char *name,
retpath = malloc(len);
if (!retpath)
return NULL;
strcpy(retpath, args.name);
strcat(retpath, "/");
(void)strlcpy(retpath, args.name, len);
strncat(retpath, "/", 1);
strncat(retpath, name, name_len);
} else {
/* we're at the root of ref_tree */
Expand Down Expand Up @@ -602,17 +602,20 @@ static bool update_tree_node(struct mytree_node *n, u64 id, u64 parent,
if (!n->name)
return false;

strcpy(n->name, name);
(void)strlcpy(n->name, name, name_len + 1);
}

if (dirname) {
n->dirname = malloc(strlen(dirname) + 1);
size_t len;

len = strlen(dirname);
n->dirname = malloc(len + 1);
if (!n->dirname) {
free(n->name);
return false;
}

strcpy(n->dirname, dirname);
(void)strlcpy(n->dirname, dirname, len + 1);
}
return true;
}
Expand Down

0 comments on commit 604f376

Please sign in to comment.