diff options
author | David Sterba <dsterba@suse.com> | 2016-01-06 14:22:34 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-01-12 15:01:06 +0100 |
commit | 8b5147d5f33e73c44aa6a0fc0f47a7e3c6b7ffb9 (patch) | |
tree | 0b22d92503482ffe1810e8aa7dc2f7ca0ba80430 | |
parent | 2cb9b4dbbd21585253a3dc314e91418ff3a9bb68 (diff) |
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>
-rw-r--r-- | mkfs.c | 8 |
1 files changed, 3 insertions, 5 deletions
@@ -591,15 +591,14 @@ static int add_symbolic_link(struct btrfs_trans_handle *trans, u64 objectid, const char *path_name) { int ret; - u64 sectorsize = root->sectorsize; - char *buf = malloc(sectorsize); + char buf[PATH_MAX]; - ret = readlink(path_name, buf, sectorsize); + ret = readlink(path_name, buf, sizeof(buf)); if (ret <= 0) { fprintf(stderr, "readlink failed for %s\n", path_name); goto fail; } - if (ret >= sectorsize) { + if (ret >= sizeof(buf)) { fprintf(stderr, "symlink too long for %s\n", path_name); ret = -1; 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, buf, ret + 1); fail: - free(buf); return ret; } |