wmbattery: avoid truncating ACPI info
commit21ab4920ad354a3ea027baa2b729d431e3225d7a
authorJeremy Sowden <jeremy@azazel.net>
Fri, 3 Jun 2022 16:46:18 +0000 (3 17:46 +0100)
committerCarlos R. Mafra <crmafra@gmail.com>
Fri, 3 Jun 2022 17:17:43 +0000 (3 18:17 +0100)
tree8d0980ef0116e416cbb5745c665e0ed82bd7fc2f
parentd9ae826d626d40e27605e6b222a24e96bcf26458
wmbattery: avoid truncating ACPI info

Hitherto, the following code has been used to read from ACPI files:

  end = read(fd, buf, sizeof(buf));
  buf[end - 1] = '\0';

This can cause problems, if we read the whole file and there is no new-line:

  $ cat /sys/module/acpi/parameters/acpica_version
  20190816$

In this case, the '\0' will overwrite the last digit, leading to spurious
error reports:

  ACPI subsystem 2019081 too is old, consider upgrading to 20011018.

Instead, read one fewer byte and write the '\0' at the next index:

  end = read(fd, buf, sizeof(buf) - 1);
  buf[end] = '\0';

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
wmbattery/acpi.c