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>
diff --git a/utils.c b/utils.c
index 9e21947..a1a387e 100644
--- a/utils.c
+++ b/utils.c
@@ -109,11 +109,18 @@
 
 	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;
 			}