diff options
author | David Sterba <dsterba@suse.com> | 2016-03-24 19:19:31 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-03-30 16:26:38 +0200 |
commit | 91b70d4cf1a1aac0ed0a9e810e0499e91244e7fd (patch) | |
tree | 261e7d95c2336ef9158dddf677f199fca6eb8029 /utils.c | |
parent | 41f6ae4820b7c288a6688086bd1a61687a50e3f3 (diff) |
btrfs-progs: use safe copy for label buffer everywhere
There's a mix of opencoded strncpy + null termination, strncpy, memcppy
without termination etc. Unify them and use the helper.
Resolves-coverity-id: 1357105
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -253,7 +253,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg) btrfs_set_super_cache_generation(&super, -1); btrfs_set_super_incompat_flags(&super, cfg->features); if (cfg->label) - strncpy(super.label, cfg->label, BTRFS_LABEL_SIZE - 1); + __strncpy_null(super.label, cfg->label, BTRFS_LABEL_SIZE - 1); /* create the tree of root objects */ memset(buf->data, 0, cfg->nodesize); @@ -1746,8 +1746,8 @@ static int set_label_unmounted(const char *dev, const char *label) return -1; trans = btrfs_start_transaction(root, 1); - snprintf(root->fs_info->super_copy->label, BTRFS_LABEL_SIZE, "%s", - label); + __strncpy_null(root->fs_info->super_copy->label, label, BTRFS_LABEL_SIZE - 1); + btrfs_commit_transaction(trans, root); /* Now we close it since we are done. */ @@ -1767,7 +1767,7 @@ static int set_label_mounted(const char *mount_path, const char *labelp) } memset(label, 0, sizeof(label)); - strncpy(label, labelp, sizeof(label)); + __strncpy_null(label, labelp, BTRFS_LABEL_SIZE - 1); if (ioctl(fd, BTRFS_IOC_SET_FSLABEL, label) < 0) { fprintf(stderr, "ERROR: unable to set label %s\n", strerror(errno)); @@ -1797,7 +1797,8 @@ int get_label_unmounted(const char *dev, char *label) if(!root) return -1; - memcpy(label, root->fs_info->super_copy->label, BTRFS_LABEL_SIZE); + __strncpy_null(label, root->fs_info->super_copy->label, + BTRFS_LABEL_SIZE - 1); /* Now we close it since we are done. */ close_ctree(root); @@ -1832,7 +1833,7 @@ int get_label_mounted(const char *mount_path, char *labelp) return ret; } - strncpy(labelp, label, sizeof(label)); + __strncpy_null(labelp, label, BTRFS_LABEL_SIZE - 1); close(fd); return 0; } |