From 8659477ea65b1617332efee6da4c533137870577 Mon Sep 17 00:00:00 2001 From: Vladis Dronov Date: Sat, 12 Jun 2021 09:00:42 +0200 Subject: Fix a read() returning zero case in init_entropy_source() Covscan warns about this with: Error: CHECKED_RETURN (CWE-252): [#def3] rng-tools-6.12/rngd_entsource.c:185: check_return: "read(int, void *, size_t)" returns the number of bytes read, but it is ignored. 185|-> if (read(rngavail_fd, buf, sizeof(buf)) < 0) { Add a check for a zero return. While this should not happen, lets just handle the case, also to silence covscan. Signed-off-by: Vladis Dronov --- rngd_entsource.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rngd_entsource.c b/rngd_entsource.c index f54ee40..e5b7d43 100644 --- a/rngd_entsource.c +++ b/rngd_entsource.c @@ -182,13 +182,14 @@ int init_entropy_source(struct rng *ent_src) return 1; } - if (read(rngavail_fd, buf, sizeof(buf)) < 0) { + int ret = read(rngavail_fd, buf, sizeof(buf)); + if (ret < 0) { message_entsrc(ent_src,LOG_DAEMON|LOG_DEBUG, "Error reading sysfs file: %s\n", RNG_AVAIL); close(rngavail_fd); return 1; } - if (strncmp(buf, "\n", 1) == 0) { + if (ret == 0 || strncmp(buf, "\n", 1) == 0) { message_entsrc(ent_src,LOG_DAEMON|LOG_DEBUG, "No available rng device\n"); close(rngavail_fd); return 1; -- 2.26.3