]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
btrfs: add to check return size of strlcat 2419/head
authorDonghwa Jeong <dh48.jeong@samsung.com>
Fri, 22 Jun 2018 05:56:40 +0000 (14:56 +0900)
committerDonghwa Jeong <dh48.jeong@samsung.com>
Fri, 22 Jun 2018 05:56:40 +0000 (14:56 +0900)
Signed-off-by: Donghwa Jeong <dh48.jeong@samsung.com>
src/lxc/storage/btrfs.c

index 0726b07c084c4ffc96705a608db51af93984bb21..f30dc47035700f2a590eeecf136d997a4430dd3a 100644 (file)
@@ -63,7 +63,7 @@ char *get_btrfs_subvol_path(int fd, u64 dir_id, u64 objid, char *name,
 {
        struct btrfs_ioctl_ino_lookup_args args;
        int ret, e;
-       size_t len;
+       size_t len, retlen;
        char *retpath;
 
        memset(&args, 0, sizeof(args));
@@ -95,16 +95,30 @@ char *get_btrfs_subvol_path(int fd, u64 dir_id, u64 objid, char *name,
 
                (void)strlcpy(retpath, args.name, len);
                (void)strlcat(retpath, "/", len);
-               (void)strlcat(retpath, name, len);
+
+               retlen = strlcat(retpath, name, len);
+               if (retlen >= len) {
+                       ERROR("Failed to append name - %s\n", name);
+                       free(retpath);
+                       return NULL;
+               }
        } else {
                /* we're at the root of ref_tree */
                len = name_len + 1;
                retpath = malloc(len);
                if (!retpath)
                        return NULL;
+
                *retpath = '\0';
-               (void)strlcat(retpath, name, len);
+
+               retlen = strlcat(retpath, name, len);
+               if (retlen >= len) {
+                       ERROR("Failed to append name - %s\n", name);
+                       free(retpath);
+                       return NULL;
+               }
        }
+
        return retpath;
 }