From 32d621e4db5b4bb83ace8bf8cfedb72e75ff3a70 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 18 Oct 2018 13:39:41 +0200 Subject: [PATCH] hwdb: fgets() excorcism --- src/libsystemd/sd-hwdb/hwdb-util.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libsystemd/sd-hwdb/hwdb-util.c b/src/libsystemd/sd-hwdb/hwdb-util.c index bfb3ae0..140ea6b 100644 --- a/src/libsystemd/sd-hwdb/hwdb-util.c +++ b/src/libsystemd/sd-hwdb/hwdb-util.c @@ -5,6 +5,7 @@ #include "alloc-util.h" #include "conf-files.h" +#include "def.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" @@ -472,7 +473,6 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr HW_DATA, } state = HW_NONE; _cleanup_fclose_ FILE *f = NULL; - char line[LINE_MAX]; _cleanup_strv_free_ char **match_list = NULL; uint32_t line_number = 0; char *match = NULL; @@ -482,10 +482,17 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr if (!f) return -errno; - while (fgets(line, sizeof(line), f)) { + for (;;) { + _cleanup_free_ char *line = NULL; size_t len; char *pos; + r = read_line(f, LONG_LINE_MAX, &line); + if (r < 0) + return r; + if (r == 0) + break; + ++line_number; /* comment line */ -- 2.7.4