summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Clark <christopher.w.clark@gmail.com>2018-08-18 18:37:14 -0700
committerBruce Ashfield <bruce.ashfield@windriver.com>2018-08-20 11:35:53 -0400
commit3266a8814259da66244b0381933ae188fcae41de (patch)
tree7944579ffd0062d636b4fc5a92549a9aa5121651
parentd8173ad1c0dde5add365e8d79596747123809a58 (diff)
downloadmeta-virtualization-3266a8814259da66244b0381933ae188fcae41de.tar.gz
xen: fix truncation warning in tools build for ARM 32-bit
Adds xen-tools-xenpmd-snprintf.patch to fix string format compiler truncation warning in xenpmd: assists the compiler by masking the value to provide an obvious low upper bound for the value range. Signed-off-by: Christopher Clark <christopher.clark6@baesystems.com> Signed-off-by: Bruce Ashfield <bruce.ashfield@windriver.com>
-rw-r--r--recipes-extended/xen/files/xen-tools-xenpmd-snprintf.patch78
-rw-r--r--recipes-extended/xen/xen_4.11.0.bb1
2 files changed, 79 insertions, 0 deletions
diff --git a/recipes-extended/xen/files/xen-tools-xenpmd-snprintf.patch b/recipes-extended/xen/files/xen-tools-xenpmd-snprintf.patch
new file mode 100644
index 00000000..aac7282f
--- /dev/null
+++ b/recipes-extended/xen/files/xen-tools-xenpmd-snprintf.patch
@@ -0,0 +1,78 @@
1From e4d78a67ffbacf30b66464080898227f18f6bf49 Mon Sep 17 00:00:00 2001
2From: Christopher Clark <christopher.w.clark@gmail.com>
3Date: Fri, 17 Aug 2018 17:46:10 -0700
4Subject: [PATCH] xenpmd: prevent format-truncation warning with gcc 8.2 + ARM
5 32-bit
6To: xen-devel@lists.xenproject.org
7Cc: ian.jackson@eu.citrix.com,
8 wei.liu2@citrix.com
9
10xenpmd writes battery information to xenstore, including a string with a
11formatted hex value calculated from summing the lengths of four strings,
12plus some constants.
13
14Each of the four strings has a maximum length of 31 bytes, excluding the
15terminating zero byte. The strings are stored in 32-byte arrays in a
16struct that is zeroed before it is populated, and logic that writes to
17the strings uses strncpy and explicit zero termination.
18
19The maximum value to be supplied to the xenstore string is:
20 (9 * 4) + (31 * 4) + 4 , which is 164, ie. 0xa4.
21
22When used with this value, '%02x' will always fit within 3 bytes, but
23gcc 8.2 is apparently not able to deduce this (observed when building
24for a 32-bit ARM platform).
25
26This commit assists the compiler by applying a mask (0xff) to the value,
27enabling it to observe a lower maximum value and so pass the truncation
28length check.
29
30Prior to this change, building fails with the compiler warning:
31
32| xenpmd.c: In function 'write_battery_info_to_xenstore':
33| xenpmd.c:354:23: error: '%02x' directive output may be truncated
34writing between 2 and 8 bytes into a region of size 3
35[-Werror=format-truncation=]
36| snprintf(val, 3, "%02x",
37| ^~~~
38| xenpmd.c:354:22: note: directive argument in the range [40, 2147483778]
39| snprintf(val, 3, "%02x",
40| ^~~~~~
41| xenpmd.c:354:5: note: 'snprintf' output between 3 and 9 bytes into a
42destination of size 3
43| snprintf(val, 3, "%02x",
44| ^~~~~~~~~~~~~~~~~~~~~~~~
45| (unsigned int)(9*4 +
46| ~~~~~~~~~~~~~~~~~~~~
47| strlen(info->model_number) +
48| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49| strlen(info->serial_number) +
50| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51| strlen(info->battery_type) +
52| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53| strlen(info->oem_info) + 4));
54| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55| cc1: all warnings being treated as errors
56
57Signed-off-by: Christopher Clark <christopher.clark6@baesystems.com>
58---
59 tools/xenpmd/xenpmd.c | 6 ++++--
60 1 file changed, 4 insertions(+), 2 deletions(-)
61
62diff --git a/tools/xenpmd/xenpmd.c b/tools/xenpmd/xenpmd.c
63index 56412a9..0c0787e 100644
64--- a/tools/xenpmd/xenpmd.c
65+++ b/tools/xenpmd/xenpmd.c
66@@ -350,8 +350,10 @@ void write_battery_info_to_xenstore(struct battery_info *info)
67
68 memset(val, 0, 1024);
69 memset(string_info, 0, 256);
70- /* write 9 dwords (so 9*4) + length of 4 strings + 4 null terminators */
71- snprintf(val, 3, "%02x",
72+ /* write 9 dwords (so 9*4) + length of 4 strings + 4 null terminators.
73+ * mask informs the compiler that format truncation will not occur.
74+ */
75+ snprintf(val, 3, "%02x", 0xff &
76 (unsigned int)(9*4 +
77 strlen(info->model_number) +
78 strlen(info->serial_number) +
diff --git a/recipes-extended/xen/xen_4.11.0.bb b/recipes-extended/xen/xen_4.11.0.bb
index d7cff324..40e73405 100644
--- a/recipes-extended/xen/xen_4.11.0.bb
+++ b/recipes-extended/xen/xen_4.11.0.bb
@@ -5,6 +5,7 @@ SRC_URI = " \
5 https://downloads.xenproject.org/release/xen/${PV}/xen-${PV}.tar.gz \ 5 https://downloads.xenproject.org/release/xen/${PV}/xen-${PV}.tar.gz \
6 file://tools-xentop-vwprintw.patch \ 6 file://tools-xentop-vwprintw.patch \
7 file://xen-4.11-arm-acpi-fix-string-lengths.patch \ 7 file://xen-4.11-arm-acpi-fix-string-lengths.patch \
8 file://xen-tools-xenpmd-snprintf.patch \
8 " 9 "
9 10
10SRC_URI[md5sum] = "cbec0600284921744bc14119f4ed3fff" 11SRC_URI[md5sum] = "cbec0600284921744bc14119f4ed3fff"