]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved-etc-hosts: FOREACH_LINE excorcism
authorLennart Poettering <lennart@poettering.net>
Thu, 18 Oct 2018 14:16:52 +0000 (16:16 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 18 Oct 2018 14:23:45 +0000 (16:23 +0200)
src/resolve/resolved-etc-hosts.c

index 5be62cc3a84f2014dbf5a6b2468dab21d86a725c..8074612fb47b30d36ad2fef678177dffbe72bc1c 100644 (file)
@@ -1,10 +1,11 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
+#include "def.h"
 #include "fd-util.h"
 #include "fileio.h"
 #include "hostname-util.h"
-#include "resolved-etc-hosts.h"
 #include "resolved-dns-synthesize.h"
+#include "resolved-etc-hosts.h"
 #include "string-util.h"
 #include "strv.h"
 #include "time-util.h"
@@ -161,13 +162,19 @@ static int parse_line(EtcHosts *hosts, unsigned nr, const char *line) {
 
 int etc_hosts_parse(EtcHosts *hosts, FILE *f) {
         _cleanup_(etc_hosts_free) EtcHosts t = {};
-        char line[LINE_MAX];
         unsigned nr = 0;
         int r;
 
-        FOREACH_LINE(line, f, return log_error_errno(errno, "Failed to read /etc/hosts: %m")) {
+        for (;;) {
+                _cleanup_free_ char *line = NULL;
                 char *l;
 
+                r = read_line(f, LONG_LINE_MAX, &line);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to read /etc/hosts: %m");
+                if (r == 0)
+                        break;
+
                 nr++;
 
                 l = strstrip(line);