aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Kicinski <kuba@kernel.org>2020-07-31 10:18:05 -0700
committerDaniel Borkmann <daniel@iogearbox.net>2020-07-31 22:40:36 +0200
commit2b9fae141fc2129940e0337732a35a3fc1c33455 (patch)
treeeaf1cb3b6c841b8272213794de5f808439bd1550
parent8c86c39ac527e70e054120ca7a9d3f235d7847ea (diff)
downloadl2md-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.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/utils.c b/utils.c
index 9e21947..a1a387e 100644
--- a/utils.c
+++ b/utils.c
@@ -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;
}