tools: guard against zero-length os-release files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1467>
This commit is contained in:
Peter Hutterer 2026-04-17 14:31:31 +10:00 committed by Marge Bot
parent 8afdc52eaf
commit a5a9d2d8df

View file

@ -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], "\"'");