File xen.2d78f78a14528752266982473c07118f1bc336e3.patch of Package xen

From: Zhongze Liu <blackskygg@gmail.com>
Date: Wed, 14 Jun 2017 09:11:48 +0800
Subject: 2d78f78a14528752266982473c07118f1bc336e3
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

tools: fix several "format-truncation" warnings with GCC 7

GCC 7.1.1 complains that several buffers passed to snprintf() in xenpmd
and tools/ocmal/xc are too small to hold the largest possible resulting string,
which is calculated by adding up the maximum length of all the substrings.

The warnings are treated as errors by -Werror, and goes like this (abbreviated):

xenpmd.c:94:36: error: ‘%s’ directive output may be truncated writing up to
255 bytes into a region of size 13 [-Werror=format-truncation=]
     #define BATTERY_INFO_FILE_PATH "/proc/acpi/battery/%s/info"
                                    ^
xenpmd.c:113:13: note: ‘snprintf’ output between 25 and 280 bytes into a
destination of size 32

xenpmd.c:95:37: error: ‘%s’ directive output may be truncated writing up to
255 bytes into a region of size 13 [-Werror=format-truncation=]
     #define BATTERY_STATE_FILE_PATH "/proc/acpi/battery/%s/state"
                                     ^
xenpmd.c:116:13: note: ‘snprintf’ output between 26 and 281 bytes into a
destination of size 32

xenctrl_stubs.c:65:15: error: ‘%s’ directive output may be truncated writing
up to 1023 bytes into a region of size 252 [-Werror=format-truncation=]
      "%d: %s: %s", error->code,
               ^~
xenctrl_stubs.c:64:4: note: ‘snprintf’ output 5 or more bytes (assuming 1028)
into a destination of size 256

Enlarge the size of these buffers as suggested by the complier
(and slightly rounded) to fix the warnings.

No functional changes.

Signed-off-by: Zhongze Liu <blackskygg@gmail.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
---
 tools/ocaml/libs/xc/xenctrl_stubs.c | 2 +-
 tools/xenpmd/xenpmd.c               | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

--- a/tools/ocaml/libs/xc/xenctrl_stubs.c
+++ b/tools/ocaml/libs/xc/xenctrl_stubs.c
@@ -44,25 +44,25 @@
 
 #define string_of_option_array(array, index) \
 	((Field(array, index) == Val_none) ? NULL : String_val(Field(Field(array, index), 0)))
 
 /* maybe here we should check the range of the input instead of blindly
  * casting it to uint32 */
 #define cpuid_input_of_val(i1, i2, input) \
 	i1 = (uint32_t) Int64_val(Field(input, 0)); \
 	i2 = ((Field(input, 1) == Val_none) ? 0xffffffff : (uint32_t) Int64_val(Field(Field(input, 1), 0)));
 
 static void Noreturn failwith_xc(xc_interface *xch)
 {
-	char error_str[256];
+	char error_str[1028];
 	if (xch) {
 		const xc_error *error = xc_get_last_error(xch);
 		if (error->code == XC_ERROR_NONE)
 			snprintf(error_str, sizeof(error_str),
 				 "%d: %s", errno, strerror(errno));
 		else
 			snprintf(error_str, sizeof(error_str),
 				 "%d: %s: %s", error->code,
 				 xc_error_code_to_desc(error->code),
 				 error->message);
 	} else {
 		snprintf(error_str, sizeof(error_str),
--- a/tools/xenpmd/xenpmd.c
+++ b/tools/xenpmd/xenpmd.c
@@ -92,38 +92,38 @@ static struct xs_handle *xs;
     #define BATTERY_STATE_FILE_PATH "/tmp/battery/%s/state"
 #else
     #define BATTERY_DIR_PATH "/proc/acpi/battery"
     #define BATTERY_INFO_FILE_PATH "/proc/acpi/battery/%s/info"
     #define BATTERY_STATE_FILE_PATH "/proc/acpi/battery/%s/state"
 #endif
 
 FILE *get_next_battery_file(DIR *battery_dir, 
                             enum BATTERY_INFO_TYPE battery_info_type)
 {
     FILE *file = 0;
     struct dirent *dir_entries;
-    char file_name[32];
+    char file_name[284];
     
     do 
     {
         dir_entries = readdir(battery_dir);
         if ( !dir_entries ) 
             return 0;
         if ( strlen(dir_entries->d_name) < 4 )
             continue;
         if ( battery_info_type == BIF ) 
-            snprintf(file_name, 32, BATTERY_INFO_FILE_PATH,
+            snprintf(file_name, sizeof(file_name), BATTERY_INFO_FILE_PATH,
                      dir_entries->d_name);
         else 
-            snprintf(file_name, 32, BATTERY_STATE_FILE_PATH,
+            snprintf(file_name, sizeof(file_name), BATTERY_STATE_FILE_PATH,
                      dir_entries->d_name);
         file = fopen(file_name, "r");
     } while ( !file );
 
     return file;
 }
 
 void set_attribute_battery_info(char *attrib_name,
                                 char *attrib_value,
                                 struct battery_info *info)
 {
     if ( strstr(attrib_name, "present") ) 
openSUSE Build Service is sponsored by