hwdb: fgets() excorcism

This commit is contained in:
Lennart Poettering
2018-10-18 13:39:41 +02:00
parent df2b06d1c2
commit 32d621e4db
+9 -2
View 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 */