mirror of
https://github.com/kdave/btrfs-progs
synced 2025-04-04 23:29:20 +00:00
btrfs-progs: use on-stack buffer in add_symbolic_link
Also get rid of the unhandled memory allocation. Resolves-coverity-id: 1338298 Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
2cb9b4dbbd
commit
8b5147d5f3
8
mkfs.c
8
mkfs.c
@ -591,15 +591,14 @@ static int add_symbolic_link(struct btrfs_trans_handle *trans,
|
|||||||
u64 objectid, const char *path_name)
|
u64 objectid, const char *path_name)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
u64 sectorsize = root->sectorsize;
|
char buf[PATH_MAX];
|
||||||
char *buf = malloc(sectorsize);
|
|
||||||
|
|
||||||
ret = readlink(path_name, buf, sectorsize);
|
ret = readlink(path_name, buf, sizeof(buf));
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
fprintf(stderr, "readlink failed for %s\n", path_name);
|
fprintf(stderr, "readlink failed for %s\n", path_name);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (ret >= sectorsize) {
|
if (ret >= sizeof(buf)) {
|
||||||
fprintf(stderr, "symlink too long for %s\n", path_name);
|
fprintf(stderr, "symlink too long for %s\n", path_name);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -609,7 +608,6 @@ static int add_symbolic_link(struct btrfs_trans_handle *trans,
|
|||||||
ret = btrfs_insert_inline_extent(trans, root, objectid, 0,
|
ret = btrfs_insert_inline_extent(trans, root, objectid, 0,
|
||||||
buf, ret + 1);
|
buf, ret + 1);
|
||||||
fail:
|
fail:
|
||||||
free(buf);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user