]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
secure coding: strcpy => strlcpy
authorDonghwa Jeong <dh48.jeong@samsung.com>
Mon, 18 Jun 2018 02:30:41 +0000 (11:30 +0900)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 10 Dec 2018 08:26:46 +0000 (09:26 +0100)
Signed-off-by: Donghwa Jeong <dh48.jeong@samsung.com>
src/lxc/criu.c
src/lxc/lxccontainer.c
src/lxc/start.c
src/lxc/storage/btrfs.c

index bf79f839b517fd7b2f39cc5142b37569b21f66c3..c1816d481da84e0439e45806edec17e6004169fb 100644 (file)
@@ -824,7 +824,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);
                }
        }
 
index eca454783182ebb23e6f2f39fd4f313513b17303..3685dc42a347054aebda6511ce2a4088ca483302 100644 (file)
@@ -1155,7 +1155,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)
@@ -4444,6 +4445,7 @@ out:
 struct lxc_container *lxc_container_new(const char *name, const char *configpath)
 {
        struct lxc_container *c;
+       size_t len;
 
        if (!name)
                return NULL;
@@ -4466,12 +4468,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);
index b5c22e1648dc121736afa7e8f640dc8859507982..a12e2ecfd6778506b0464df9264c908b96ea471f 100644 (file)
@@ -103,9 +103,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++;
index 511e6a03fb06e13947dd397bde08c15009225c09..c351bee67e056b00e727d53c1c25e8cf4646dd5d 100644 (file)
@@ -91,8 +91,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 */
@@ -521,17 +521,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;
 }