diff options
author | Jakub Kicinski <kuba@kernel.org> | 2020-07-31 10:18:05 -0700 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2020-07-31 22:40:36 +0200 |
commit | 2b9fae141fc2129940e0337732a35a3fc1c33455 (patch) | |
tree | eaf1cb3b6c841b8272213794de5f808439bd1550 | |
parent | 8c86c39ac527e70e054120ca7a9d3f235d7847ea (diff) | |
download | l2md-2b9fae141fc2129940e0337732a35a3fc1c33455.tar.gz |
l2md: fix infinite loop on reading short files
When (config) files get corrupted and are not the expected
size we'd enter an infinite loop.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-rw-r--r-- | utils.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -109,11 +109,18 @@ int xread_file(const char *file, char *to, size_t len, bool fatal) do { ret = read(fd, to, len); - if (ret < 0) { + if (ret <= 0) { if (fatal) { - panic("Cannot read file %s: %s\n", file, - strerror(errno)); + if (ret) + panic("Cannot read file %s: %s\n", + file, strerror(errno)); + else + panic("Unexpected end of file %s\n", + file); } else { + if (!ret) + warn("Unexpected end of file %s\n", + file); close(fd); return -1; } |