btrfs: add to check return size of strlcat

parent ebcd5140
...@@ -63,7 +63,7 @@ char *get_btrfs_subvol_path(int fd, u64 dir_id, u64 objid, char *name, ...@@ -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; struct btrfs_ioctl_ino_lookup_args args;
int ret, e; int ret, e;
size_t len; size_t len, retlen;
char *retpath; char *retpath;
memset(&args, 0, sizeof(args)); memset(&args, 0, sizeof(args));
...@@ -95,16 +95,30 @@ char *get_btrfs_subvol_path(int fd, u64 dir_id, u64 objid, char *name, ...@@ -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)strlcpy(retpath, args.name, len);
(void)strlcat(retpath, "/", 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 { } else {
/* we're at the root of ref_tree */ /* we're at the root of ref_tree */
len = name_len + 1; len = name_len + 1;
retpath = malloc(len); retpath = malloc(len);
if (!retpath) if (!retpath)
return NULL; return NULL;
*retpath = '\0'; *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; return retpath;
} }
......
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