From 55299db6f5fe4ae0e784c77ec16c66c71a18f2e8 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 17 Dec 2016 18:39:39 +0100 Subject: [PATCH] battery plugin: null-terminate buffer We call strstripnewline on it, which expects a null-terminated string. CID #158524 --- src/battery.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/battery.c b/src/battery.c index 5c02fee2..78e96b25 100644 --- a/src/battery.c +++ b/src/battery.c @@ -350,10 +350,12 @@ static int sysfs_file_to_buffer(char const *dir, /* {{{ */ ssnprintf(filename, sizeof(filename), "%s/%s/%s", dir, power_supply, basename); - status = (int)read_file_contents(filename, buffer, buffer_size); + status = (int)read_file_contents(filename, buffer, buffer_size - 1); if (status < 0) return status; + buffer[status] = '\0'; + strstripnewline(buffer); return 0; } /* }}} int sysfs_file_to_buffer */ @@ -364,7 +366,7 @@ static int sysfs_file_to_gauge(char const *dir, /* {{{ */ char const *power_supply, char const *basename, gauge_t *ret_value) { int status; - char buffer[32] = ""; + char buffer[32]; status = sysfs_file_to_buffer(dir, power_supply, basename, buffer, sizeof(buffer)); -- 2.30.2