]> sourceware.org Git - lvm2.git/commitdiff
Fix _get_proc_number to be tolerant of malformed /proc/misc entries.
authorMike Snitzer <snitzer@redhat.com>
Tue, 8 Nov 2011 17:32:10 +0000 (17:32 +0000)
committerMike Snitzer <snitzer@redhat.com>
Tue, 8 Nov 2011 17:32:10 +0000 (17:32 +0000)
Fixes issue reported here: http://lkml.org/lkml/2011/11/8/190

WHATS_NEW_DM
libdm/ioctl/libdm-iface.c

index de4eaa2d82afbd5ec4437cacc59b76970322ad8f..1755f80cbb809d7d7f8618da7725f8818dd0bf13 100644 (file)
@@ -1,5 +1,6 @@
 Version 1.02.68 -
 ==================================
+  Fix _get_proc_number to be tolerant of malformed /proc/misc entries.
   Add ExecReload to dm-event.service for systemd to reload dmeventd properly.
   Add dm_config_tree_find_str_allow_empty.
   Fix compile-time pool memory locking with DEBUG_MEM.
index 707d4409be1a4f77a0a7ce3ddb87007b589458ff..f28ed487384fa6c94a08453eb3f4c7ec5aa4af03 100644 (file)
@@ -172,7 +172,8 @@ static int _get_proc_number(const char *file, const char *name,
 {
        FILE *fl;
        char nm[256];
-       int c;
+       char *line;
+       size_t len;
        uint32_t num;
 
        if (!(fl = fopen(file, "r"))) {
@@ -180,8 +181,8 @@ static int _get_proc_number(const char *file, const char *name,
                return 0;
        }
 
-       while (!feof(fl)) {
-               if (fscanf(fl, "%d %255s\n", &num, &nm[0]) == 2) {
+       while (getline(&line, &len, fl) != -1) {
+               if (sscanf(line, "%d %255s\n", &num, &nm[0]) == 2) {
                        if (!strcmp(name, nm)) {
                                if (number) {
                                        *number = num;
@@ -191,9 +192,7 @@ static int _get_proc_number(const char *file, const char *name,
                                }
                                dm_bit_set(_dm_bitset, num);
                        }
-               } else do {
-                       c = fgetc(fl);
-               } while (c != EOF && c != '\n');
+               }
        }
        if (fclose(fl))
                log_sys_error("fclose", file);
This page took 0.032593 seconds and 5 git commands to generate.