diff options
author | Jeff Liu <jeff.liu@oracle.com> | 2012-12-17 11:35:27 +0000 |
---|---|---|
committer | David Sterba <dsterba@suse.cz> | 2013-02-26 19:24:14 +0100 |
commit | 3988e807025b6f2a0b2d26d21bdbfecf29f0aecb (patch) | |
tree | c07382aa2195c75aebb86acb3e1b800e928aff72 | |
parent | 619dc61cae1420da2dec48f689d49b9b346abc15 (diff) |
Btrfs-progs: Fix set_label_unmounted() with label length validation
Currently, we keeping silent if the label length is exceeding BTRFS_LABEL_SIZE - 1, and just
truncating the characters beyond that.
This patch make it return error and exit in this situation.
Signed-off-by: Jie Liu <jeff.liu@oracle.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
-rw-r--r-- | btrfslabel.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/btrfslabel.c b/btrfslabel.c index 7aea996e..dcc776e5 100644 --- a/btrfslabel.c +++ b/btrfslabel.c @@ -63,6 +63,12 @@ static int set_label_unmounted(const char *dev, const char *label) return -1; } + if (strlen(label) > BTRFS_LABEL_SIZE - 1) { + fprintf(stderr, "ERROR: Label %s is too long (max %d)\n", + label, BTRFS_LABEL_SIZE - 1); + return -1; + } + /* Open the super_block at the default location * and as read-write. */ @@ -71,8 +77,8 @@ static int set_label_unmounted(const char *dev, const char *label) return -1; trans = btrfs_start_transaction(root, 1); - strncpy(root->fs_info->super_copy.label, label, BTRFS_LABEL_SIZE); - root->fs_info->super_copy.label[BTRFS_LABEL_SIZE-1] = 0; + snprintf(root->fs_info->super_copy.label, BTRFS_LABEL_SIZE, "%s", + label); btrfs_commit_transaction(trans, root); /* Now we close it since we are done. */ |