From: Ruben Kerkhof Date: Sat, 17 Dec 2016 17:39:39 +0000 (+0100) Subject: battery plugin: null-terminate buffer X-Git-Tag: collectd-5.7.1~10^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=55299db6f5fe4ae0e784c77ec16c66c71a18f2e8;p=collectd.git battery plugin: null-terminate buffer We call strstripnewline on it, which expects a null-terminated string. CID #158524 --- 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));