]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hwdb: fgets() excorcism
authorLennart Poettering <lennart@poettering.net>
Thu, 18 Oct 2018 11:39:41 +0000 (13:39 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 18 Oct 2018 11:39:41 +0000 (13:39 +0200)
src/libsystemd/sd-hwdb/hwdb-util.c

index bfb3ae0e9c5447ae40144582ce19a01c61aacaa7..140ea6b591f7964757820cf9174d8904c048d9f1 100644 (file)
@@ -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 */