[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 2/3] tools/xenpmd: fix potential string truncation



GCC 7 warns (and thanks to -Werror, fails) about potential string
truncation by snprintf in get_next_battery_file. Since the code already
check if string is no longer than 4 chars, tell gcc about it.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>
---
 tools/xenpmd/xenpmd.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/xenpmd/xenpmd.c b/tools/xenpmd/xenpmd.c
index b3a3106..ed6635b 100644
--- a/tools/xenpmd/xenpmd.c
+++ b/tools/xenpmd/xenpmd.c
@@ -87,12 +87,12 @@ static struct xs_handle *xs;
 
 #ifdef RUN_IN_SIMULATE_MODE
     #define BATTERY_DIR_PATH "/tmp/battery"
-    #define BATTERY_INFO_FILE_PATH "/tmp/battery/%s/info" 
-    #define BATTERY_STATE_FILE_PATH "/tmp/battery/%s/state"
+    #define BATTERY_INFO_FILE_PATH "/tmp/battery/%.4s/info"
+    #define BATTERY_STATE_FILE_PATH "/tmp/battery/%.4s/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"
+    #define BATTERY_INFO_FILE_PATH "/proc/acpi/battery/%.4s/info"
+    #define BATTERY_STATE_FILE_PATH "/proc/acpi/battery/%.4s/state"
 #endif
 
 FILE *get_next_battery_file(DIR *battery_dir, 
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.