diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-10-18 13:34:40 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-10-18 13:34:40 +0200 |
commit | b42674a1681617f0a8bef6a2f3c17e22c048d854 (patch) | |
tree | 6a364eced7e5d3fa58417045319943107dd5a3b8 /src/cryptsetup/cryptsetup-generator.c | |
parent | cgtop: fgets() excorcism (diff) | |
download | systemd-b42674a1681617f0a8bef6a2f3c17e22c048d854.tar.xz systemd-b42674a1681617f0a8bef6a2f3c17e22c048d854.zip |
cryptsetup-generator: fgets() excorcism
Diffstat (limited to 'src/cryptsetup/cryptsetup-generator.c')
-rw-r--r-- | src/cryptsetup/cryptsetup-generator.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index cada032bb9..c3a4509030 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -4,6 +4,7 @@ #include <stdio_ext.h> #include "alloc-util.h" +#include "def.h" #include "dropin.h" #include "fd-util.h" #include "fileio.h" @@ -443,9 +444,10 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat } static int add_crypttab_devices(void) { - struct stat st; - unsigned crypttab_line = 0; _cleanup_fclose_ FILE *f = NULL; + unsigned crypttab_line = 0; + struct stat st; + int r; if (!arg_read_crypttab) return 0; @@ -465,18 +467,21 @@ static int add_crypttab_devices(void) { } for (;;) { - int r, k; - char line[LINE_MAX], *l, *uuid; + _cleanup_free_ char *line = NULL, *name = NULL, *device = NULL, *keyfile = NULL, *options = NULL; crypto_device *d = NULL; - _cleanup_free_ char *name = NULL, *device = NULL, *keyfile = NULL, *options = NULL; + char *l, *uuid; + int k; - if (!fgets(line, sizeof(line), f)) + r = read_line(f, LONG_LINE_MAX, &line); + if (r < 0) + return log_error_errno(r, "Failed to read /etc/crypttab: %m"); + if (r == 0) break; crypttab_line++; l = strstrip(line); - if (IN_SET(*l, 0, '#')) + if (IN_SET(l[0], 0, '#')) continue; k = sscanf(l, "%ms %ms %ms %ms", &name, &device, &keyfile, &options); |