summaryrefslogtreecommitdiff
path: root/mkfs.c
diff options
context:
space:
mode:
authorSergei Trofimovich <slyfox@gentoo.org>2011-06-04 11:19:20 +0300
committerChris Mason <chris.mason@oracle.com>2011-10-25 09:18:58 -0400
commitf509f1762e054c3f9bd5e4321dce9240bfd5b03a (patch)
tree47e96b204f7d97f1661f9dc403962b53d1a0646e /mkfs.c
parent891dea4f00c44cda9a3437da45683d96db69a33c (diff)
mkfs.btrfs: fix symlink names writing
Found by valgrind: ==8968== Use of uninitialised value of size 8 ==8968== at 0x41CE7D: crc32c_le (crc32c.c:98) ==8968== by 0x40A1D0: csum_tree_block_size (disk-io.c:82) ==8968== by 0x40A2D4: csum_tree_block (disk-io.c:105) ==8968== by 0x40A7D6: write_tree_block (disk-io.c:241) ==8968== by 0x40ACEE: __commit_transaction (disk-io.c:354) ==8968== by 0x40AE9E: btrfs_commit_transaction (disk-io.c:385) ==8968== by 0x42CF66: make_image (mkfs.c:1061) ==8968== by 0x42DE63: main (mkfs.c:1410) ==8968== Uninitialised value was created by a stack allocation ==8968== at 0x42B5FB: add_inode_items (mkfs.c:493) readlink(2) does not write '\0' for us, so make it manually. Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org> Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
Diffstat (limited to 'mkfs.c')
-rw-r--r--mkfs.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/mkfs.c b/mkfs.c
index efd85d58..5e483dcf 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -709,11 +709,13 @@ static int add_symbolic_link(struct btrfs_trans_handle *trans,
fprintf(stderr, "readlink failed for %s\n", path_name);
goto fail;
}
- if (ret > sectorsize) {
+ if (ret >= sectorsize) {
fprintf(stderr, "symlink too long for %s", path_name);
ret = -1;
goto fail;
}
+
+ buf[ret] = '\0'; /* readlink does not do it for us */
ret = btrfs_insert_inline_extent(trans, root, objectid, 0,
buf, ret + 1);
fail: