summaryrefslogtreecommitdiffstats
path: root/meta/recipes-extended/mdadm/files/0003-Replace-snprintf-with-strncpy-at-some-places-to-avoi.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-extended/mdadm/files/0003-Replace-snprintf-with-strncpy-at-some-places-to-avoi.patch')
-rw-r--r--meta/recipes-extended/mdadm/files/0003-Replace-snprintf-with-strncpy-at-some-places-to-avoi.patch59
1 files changed, 59 insertions, 0 deletions
diff --git a/meta/recipes-extended/mdadm/files/0003-Replace-snprintf-with-strncpy-at-some-places-to-avoi.patch b/meta/recipes-extended/mdadm/files/0003-Replace-snprintf-with-strncpy-at-some-places-to-avoi.patch
new file mode 100644
index 0000000000..dcec84ffcd
--- /dev/null
+++ b/meta/recipes-extended/mdadm/files/0003-Replace-snprintf-with-strncpy-at-some-places-to-avoi.patch
@@ -0,0 +1,59 @@
1From bc87af1314325b00c6ac002a60a2b0f0caa81e34 Mon Sep 17 00:00:00 2001
2From: Xiao Ni <xni@redhat.com>
3Date: Sat, 18 Mar 2017 10:33:44 +0800
4Subject: [PATCH 3/5] Replace snprintf with strncpy at some places to avoid
5 truncation
6
7In gcc7 there are some building errors like:
8directive output may be truncated writing up to 31 bytes into a region of size 24
9snprintf(str, MPB_SIG_LEN, %s, mpb->sig);
10
11It just need to copy one string to target. So use strncpy to replace it.
12
13For this line code: snprintf(str, MPB_SIG_LEN, %s, mpb->sig);
14Because mpb->sig has the content of version after magic, so
15it's better to use strncpy to replace snprintf too.
16
17Signed-off-by: Xiao Ni <xni@redhat.com>
18Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
19---
20Upstream-Status: Backport
21 super-intel.c | 9 ++++++---
22 1 file changed, 6 insertions(+), 3 deletions(-)
23
24diff --git a/super-intel.c b/super-intel.c
25index 57c7e75..5499098 100644
26--- a/super-intel.c
27+++ b/super-intel.c
28@@ -1811,7 +1811,8 @@ static void examine_super_imsm(struct supertype *st, char *homehost)
29 __u32 reserved = imsm_reserved_sectors(super, super->disks);
30 struct dl *dl;
31
32- snprintf(str, MPB_SIG_LEN, "%s", mpb->sig);
33+ strncpy(str, (char *)mpb->sig, MPB_SIG_LEN);
34+ str[MPB_SIG_LEN-1] = '\0';
35 printf(" Magic : %s\n", str);
36 snprintf(str, strlen(MPB_VERSION_RAID0), "%s", get_imsm_version(mpb));
37 printf(" Version : %s\n", get_imsm_version(mpb));
38@@ -7142,14 +7143,16 @@ static int update_subarray_imsm(struct supertype *st, char *subarray,
39
40 u->type = update_rename_array;
41 u->dev_idx = vol;
42- snprintf((char *) u->name, MAX_RAID_SERIAL_LEN, "%s", name);
43+ strncpy((char *) u->name, name, MAX_RAID_SERIAL_LEN);
44+ u->name[MAX_RAID_SERIAL_LEN-1] = '\0';
45 append_metadata_update(st, u, sizeof(*u));
46 } else {
47 struct imsm_dev *dev;
48 int i;
49
50 dev = get_imsm_dev(super, vol);
51- snprintf((char *) dev->volume, MAX_RAID_SERIAL_LEN, "%s", name);
52+ strncpy((char *) dev->volume, name, MAX_RAID_SERIAL_LEN);
53+ dev->volume[MAX_RAID_SERIAL_LEN-1] = '\0';
54 for (i = 0; i < mpb->num_raid_devs; i++) {
55 dev = get_imsm_dev(super, i);
56 handle_missing(super, dev);
57--
582.12.2
59