]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-rules: fgets() excorcism 10447/head
authorLennart Poettering <lennart@poettering.net>
Thu, 18 Oct 2018 11:41:09 +0000 (13:41 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 18 Oct 2018 11:41:09 +0000 (13:41 +0200)
src/udev/udev-rules.c

index 752e17f2aed0b4d9eb77072fa0996b50a945398f..f834028dec6da6ea48899caf7f1704a84cbce75d 100644 (file)
 
 #include "alloc-util.h"
 #include "conf-files.h"
+#include "def.h"
 #include "dirent-util.h"
 #include "escape.h"
 #include "fd-util.h"
+#include "fileio.h"
 #include "fs-util.h"
 #include "glob-util.h"
 #include "path-util.h"
@@ -613,15 +615,25 @@ static int import_property_from_string(struct udev_device *dev, char *line) {
 }
 
 static int import_file_into_properties(struct udev_device *dev, const char *filename) {
-        FILE *f;
-        char line[UTIL_LINE_SIZE];
+        _cleanup_fclose_ FILE *f = NULL;
+        int r;
 
         f = fopen(filename, "re");
-        if (f == NULL)
-                return -1;
-        while (fgets(line, sizeof(line), f) != NULL)
-                import_property_from_string(dev, line);
-        fclose(f);
+        if (!f)
+                return -errno;
+
+        for (;;) {
+                _cleanup_free_ char *line = NULL;
+
+                r = read_line(f, LONG_LINE_MAX, &line);
+                if (r < 0)
+                        return r;
+                if (r == 0)
+                        break;
+
+                (void) import_property_from_string(dev, line);
+        }
+
         return 0;
 }
 
@@ -646,7 +658,7 @@ static int import_program_into_properties(struct udev_event *event,
                         pos[0] = '\0';
                         pos = &pos[1];
                 }
-                import_property_from_string(event->dev, line);
+                (void) import_property_from_string(event->dev, line);
                 line = pos;
         }
         return 0;
@@ -1429,8 +1441,8 @@ static int parse_file(struct udev_rules *rules, const char *filename) {
         if (!f) {
                 if (errno == ENOENT)
                         return 0;
-                else
-                        return -errno;
+
+                return -errno;
         }
 
         if (null_or_empty_fd(fileno(f))) {