summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0002-Btrfs-progs-use-safe-string-manipulation-functions.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0002-Btrfs-progs-use-safe-string-manipulation-functions.patch')
-rw-r--r--meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0002-Btrfs-progs-use-safe-string-manipulation-functions.patch152
1 files changed, 152 insertions, 0 deletions
diff --git a/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0002-Btrfs-progs-use-safe-string-manipulation-functions.patch b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0002-Btrfs-progs-use-safe-string-manipulation-functions.patch
new file mode 100644
index 0000000000..67739be2f4
--- /dev/null
+++ b/meta/recipes-devtools/btrfs-tools/btrfs-tools/upstream-tmp/0002-Btrfs-progs-use-safe-string-manipulation-functions.patch
@@ -0,0 +1,152 @@
1Upstream-Status: Inappropriate [Backport]
2From 2636bf1da17720fc99b14cf4db33f1d1a4c9e0ee Mon Sep 17 00:00:00 2001
3From: Eduardo Silva <eduardo.silva@oracle.com>
4Date: Mon, 7 Feb 2011 08:55:04 -0300
5Subject: [PATCH 02/15] Btrfs-progs use safe string manipulation functions
6
7Signed-off-by: Eduardo Silva <eduardo.silva@oracle.com>
8Signed-off-by: Chris Mason <chris.mason@oracle.com>
9---
10 btrfs_cmds.c | 14 +++++++-------
11 btrfsctl.c | 2 +-
12 convert.c | 2 +-
13 utils.c | 9 +++++----
14 4 files changed, 14 insertions(+), 13 deletions(-)
15
16diff --git a/btrfs_cmds.c b/btrfs_cmds.c
17index 8031c58..fffb423 100644
18--- a/btrfs_cmds.c
19+++ b/btrfs_cmds.c
20@@ -375,7 +375,7 @@ int do_clone(int argc, char **argv)
21 printf("Create a snapshot of '%s' in '%s/%s'\n",
22 subvol, dstdir, newname);
23 args.fd = fd;
24- strcpy(args.name, newname);
25+ strncpy(args.name, newname, BTRFS_PATH_NAME_MAX);
26 res = ioctl(fddst, BTRFS_IOC_SNAP_CREATE, &args);
27
28 close(fd);
29@@ -436,7 +436,7 @@ int do_delete_subvolume(int argc, char **argv)
30 }
31
32 printf("Delete subvolume '%s/%s'\n", dname, vname);
33- strcpy(args.name, vname);
34+ strncpy(args.name, vname, BTRFS_PATH_NAME_MAX);
35 res = ioctl(fd, BTRFS_IOC_SNAP_DESTROY, &args);
36
37 close(fd);
38@@ -490,7 +490,7 @@ int do_create_subvol(int argc, char **argv)
39 }
40
41 printf("Create subvolume '%s/%s'\n", dstdir, newname);
42- strcpy(args.name, newname);
43+ strncpy(args.name, newname, BTRFS_PATH_NAME_MAX);
44 res = ioctl(fddst, BTRFS_IOC_SUBVOL_CREATE, &args);
45
46 close(fddst);
47@@ -553,7 +553,7 @@ int do_scan(int argc, char **argv)
48
49 printf("Scanning for Btrfs filesystems in '%s'\n", argv[i]);
50
51- strcpy(args.name, argv[i]);
52+ strncpy(args.name, argv[i], BTRFS_PATH_NAME_MAX);
53 /*
54 * FIXME: which are the error code returned by this ioctl ?
55 * it seems that is impossible to understand if there no is
56@@ -593,7 +593,7 @@ int do_resize(int argc, char **argv)
57 }
58
59 printf("Resize '%s' of '%s'\n", path, amount);
60- strcpy(args.name, amount);
61+ strncpy(args.name, amount, BTRFS_PATH_NAME_MAX);
62 res = ioctl(fd, BTRFS_IOC_RESIZE, &args);
63 close(fd);
64 if( res < 0 ){
65@@ -736,7 +736,7 @@ int do_add_volume(int nargs, char **args)
66 }
67 close(devfd);
68
69- strcpy(ioctl_args.name, args[i]);
70+ strncpy(ioctl_args.name, args[i], BTRFS_PATH_NAME_MAX);
71 res = ioctl(fdmnt, BTRFS_IOC_ADD_DEV, &ioctl_args);
72 if(res<0){
73 fprintf(stderr, "ERROR: error adding the device '%s'\n", args[i]);
74@@ -792,7 +792,7 @@ int do_remove_volume(int nargs, char **args)
75 struct btrfs_ioctl_vol_args arg;
76 int res;
77
78- strcpy(arg.name, args[i]);
79+ strncpy(arg.name, args[i], BTRFS_PATH_NAME_MAX);
80 res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg);
81 if(res<0){
82 fprintf(stderr, "ERROR: error removing the device '%s'\n", args[i]);
83diff --git a/btrfsctl.c b/btrfsctl.c
84index 92bdf39..adfa519 100644
85--- a/btrfsctl.c
86+++ b/btrfsctl.c
87@@ -237,7 +237,7 @@ int main(int ac, char **av)
88 }
89
90 if (name)
91- strcpy(args.name, name);
92+ strncpy(args.name, name, BTRFS_PATH_NAME_MAX + 1);
93 else
94 args.name[0] = '\0';
95
96diff --git a/convert.c b/convert.c
97index d037c98..fbcf4a3 100644
98--- a/convert.c
99+++ b/convert.c
100@@ -857,7 +857,7 @@ static int copy_single_xattr(struct btrfs_trans_handle *trans,
101 data = databuf;
102 datalen = bufsize;
103 }
104- strcpy(namebuf, xattr_prefix_table[name_index]);
105+ strncpy(namebuf, xattr_prefix_table[name_index], XATTR_NAME_MAX);
106 strncat(namebuf, EXT2_EXT_ATTR_NAME(entry), entry->e_name_len);
107 if (name_len + datalen > BTRFS_LEAF_DATA_SIZE(root) -
108 sizeof(struct btrfs_item) - sizeof(struct btrfs_dir_item)) {
109diff --git a/utils.c b/utils.c
110index fd894f3..96ef94d 100644
111--- a/utils.c
112+++ b/utils.c
113@@ -108,7 +108,7 @@ int make_btrfs(int fd, const char *device, const char *label,
114 btrfs_set_super_csum_type(&super, BTRFS_CSUM_TYPE_CRC32);
115 btrfs_set_super_chunk_root_generation(&super, 1);
116 if (label)
117- strcpy(super.label, label);
118+ strncpy(super.label, label, BTRFS_LABEL_SIZE - 1);
119
120 buf = malloc(sizeof(*buf) + max(sectorsize, leafsize));
121
122@@ -828,7 +828,7 @@ void btrfs_register_one_device(char *fname)
123 "skipping device registration\n");
124 return;
125 }
126- strcpy(args.name, fname);
127+ strncpy(args.name, fname, BTRFS_PATH_NAME_MAX);
128 ret = ioctl(fd, BTRFS_IOC_SCAN_DEV, &args);
129 close(fd);
130 }
131@@ -971,6 +971,7 @@ static char *size_strs[] = { "", "KB", "MB", "GB", "TB",
132 char *pretty_sizes(u64 size)
133 {
134 int num_divs = 0;
135+ int pretty_len = 16;
136 u64 last_size = size;
137 u64 fract_size = size;
138 float fraction;
139@@ -988,8 +989,8 @@ char *pretty_sizes(u64 size)
140 return NULL;
141
142 fraction = (float)fract_size / 1024;
143- pretty = malloc(16);
144- sprintf(pretty, "%.2f%s", fraction, size_strs[num_divs-1]);
145+ pretty = malloc(pretty_len);
146+ snprintf(pretty, pretty_len, "%.2f%s", fraction, size_strs[num_divs-1]);
147 return pretty;
148 }
149
150--
1511.7.2.3
152