diff options
author | David Sterba <dsterba@suse.com> | 2015-09-02 18:02:23 +0200 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2015-09-02 18:56:54 +0200 |
commit | a426f18baf519f6694ef923bd7d046041d190dee (patch) | |
tree | 00d628633aacc315f205fc623d406fa4b4068eb2 /btrfs-convert.c | |
parent | 13be89d82ee9a233a30e7ed1ef09dff242dfcaa6 (diff) |
btrfs-progs: convert: rework checks of label size
Coverity complains that the fslabel might be longer than the superblock
buffer, down in do_convert.
The label is at most 255 bytes, terminated by zero. Use buffers of the
right size.
Resolves-coverity-id: 1320911
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'btrfs-convert.c')
-rw-r--r-- | btrfs-convert.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/btrfs-convert.c b/btrfs-convert.c index 2e6f4d4c..f4fc650f 100644 --- a/btrfs-convert.c +++ b/btrfs-convert.c @@ -2868,7 +2868,7 @@ int main(int argc, char *argv[]) int usage_error = 0; int progress = 1; char *file; - char fslabel[BTRFS_LABEL_SIZE + 1]; + char fslabel[BTRFS_LABEL_SIZE]; u64 features = BTRFS_MKFS_DEFAULT_FEATURES; while(1) { @@ -2910,14 +2910,13 @@ int main(int argc, char *argv[]) break; case 'l': copylabel = -1; - fslabel[BTRFS_LABEL_SIZE] = 0; - strncpy(fslabel, optarg, sizeof(fslabel)); - if (fslabel[BTRFS_LABEL_SIZE]) { + if (strlen(optarg) >= BTRFS_LABEL_SIZE) { fprintf(stderr, - "warning: label too long, trimmed to %d bytes\n", - BTRFS_LABEL_SIZE); - fslabel[BTRFS_LABEL_SIZE] = 0; + "WARNING: label too long, trimmed to %d bytes\n", + BTRFS_LABEL_SIZE - 1); } + strncpy(fslabel, optarg, BTRFS_LABEL_SIZE - 1); + fslabel[BTRFS_LABEL_SIZE - 1] = 0; break; case 'L': copylabel = 1; |