summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorEduardo Silva <eduardo.silva@oracle.com>2011-02-07 08:55:04 -0300
committerChris Mason <chris.mason@oracle.com>2011-10-25 09:18:31 -0400
commit16261f09c4cef8f88a902108d7b78a17d775028c (patch)
treeca54e12b973332768e4dc44ba53f4ab4128913bb /utils.c
parentb4382217f18a27be16f9a960ac3b1327c87297e7 (diff)
Btrfs-progs use safe string manipulation functions
Signed-off-by: Eduardo Silva <eduardo.silva@oracle.com> Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/utils.c b/utils.c
index fd894f3b..96ef94d3 100644
--- a/utils.c
+++ b/utils.c
@@ -108,7 +108,7 @@ int make_btrfs(int fd, const char *device, const char *label,
btrfs_set_super_csum_type(&super, BTRFS_CSUM_TYPE_CRC32);
btrfs_set_super_chunk_root_generation(&super, 1);
if (label)
- strcpy(super.label, label);
+ strncpy(super.label, label, BTRFS_LABEL_SIZE - 1);
buf = malloc(sizeof(*buf) + max(sectorsize, leafsize));
@@ -828,7 +828,7 @@ void btrfs_register_one_device(char *fname)
"skipping device registration\n");
return;
}
- strcpy(args.name, fname);
+ strncpy(args.name, fname, BTRFS_PATH_NAME_MAX);
ret = ioctl(fd, BTRFS_IOC_SCAN_DEV, &args);
close(fd);
}
@@ -971,6 +971,7 @@ static char *size_strs[] = { "", "KB", "MB", "GB", "TB",
char *pretty_sizes(u64 size)
{
int num_divs = 0;
+ int pretty_len = 16;
u64 last_size = size;
u64 fract_size = size;
float fraction;
@@ -988,8 +989,8 @@ char *pretty_sizes(u64 size)
return NULL;
fraction = (float)fract_size / 1024;
- pretty = malloc(16);
- sprintf(pretty, "%.2f%s", fraction, size_strs[num_divs-1]);
+ pretty = malloc(pretty_len);
+ snprintf(pretty, pretty_len, "%.2f%s", fraction, size_strs[num_divs-1]);
return pretty;
}