From a5a9d2d8dfe2f192af9cb17dae16142c7b7eda8d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 17 Apr 2026 14:31:31 +1000 Subject: [PATCH] tools: guard against zero-length os-release files Co-Authored-By: Claude Opus 4.6 Part-of: --- tools/libinput-record.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/libinput-record.c b/tools/libinput-record.c index f3e2c0e8..1cff07e8 100644 --- a/tools/libinput-record.c +++ b/tools/libinput-record.c @@ -1379,7 +1379,9 @@ print_system_header(FILE *fp) char osrstr[256] = "unknown"; while (fgets(osrstr, sizeof(osrstr), osrelease)) { - osrstr[strlen(osrstr) - 1] = '\0'; /* linebreak */ + size_t len = strlen(osrstr); + if (len > 0 && osrstr[len - 1] == '\n') + osrstr[len - 1] = '\0'; /* linebreak */ if (!distro && strstartswith(osrstr, "ID=")) distro = strstrip(&osrstr[3], "\"'");