Skip to content

Commit 32d621e

Browse files
committed
hwdb: fgets() excorcism
1 parent df2b06d commit 32d621e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/libsystemd/sd-hwdb/hwdb-util.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "alloc-util.h"
77
#include "conf-files.h"
8+
#include "def.h"
89
#include "fd-util.h"
910
#include "fileio.h"
1011
#include "fs-util.h"
@@ -472,7 +473,6 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr
472473
HW_DATA,
473474
} state = HW_NONE;
474475
_cleanup_fclose_ FILE *f = NULL;
475-
char line[LINE_MAX];
476476
_cleanup_strv_free_ char **match_list = NULL;
477477
uint32_t line_number = 0;
478478
char *match = NULL;
@@ -482,10 +482,17 @@ static int import_file(struct trie *trie, const char *filename, uint16_t file_pr
482482
if (!f)
483483
return -errno;
484484

485-
while (fgets(line, sizeof(line), f)) {
485+
for (;;) {
486+
_cleanup_free_ char *line = NULL;
486487
size_t len;
487488
char *pos;
488489

490+
r = read_line(f, LONG_LINE_MAX, &line);
491+
if (r < 0)
492+
return r;
493+
if (r == 0)
494+
break;
495+
489496
++line_number;
490497

491498
/* comment line */

0 commit comments

Comments
 (0)