From 29a910069e5872ce1ba3e6370829362540fd67e9 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 15 Mar 2020 11:02:53 +0000 Subject: [PATCH] main: write error if password cannot be read Signed-off-by: Heinrich Schuchardt --- src/main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index a195edb..6e83e8b 100644 --- a/src/main.c +++ b/src/main.c @@ -56,6 +56,7 @@ static void read_password(void) const char filename[] = "/etc/sispmctl/password"; char buf[BUFSIZE]; char *pos; + size_t len; file = fopen(filename, "r"); if (!file) { @@ -67,7 +68,11 @@ static void read_password(void) return; } memset(buf, 0, BUFSIZE); - fread(buf, 1, BUFSIZE - 1, file); + len = fread(buf, 1, BUFSIZE - 1, file); + if (!len) { + fprintf(stderr, "Failed to read password\n"); + exit(EXIT_FAILURE); + } pos = strchr(buf, '\n'); if (pos) { *pos = '\0';