From d47951c6e13c4b8b037343e8c6f31d926ba9f455 Mon Sep 17 00:00:00 2001 From: Vitaly Chikunov Date: Mon, 15 Jul 2019 23:05:49 +0300 Subject: [PATCH] ima-evm-utils: Fix null dereference from file2bin to memcpy file2bin() may return NULL, which is set to tmp, which is passed to memcpy. Add explicit check for it. Fixes: CID 229904. Signed-off-by: Vitaly Chikunov Signed-off-by: Mimi Zohar --- src/evmctl.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/evmctl.c b/src/evmctl.c index a6d07c9..d6e0b2c 100644 --- a/src/evmctl.c +++ b/src/evmctl.c @@ -821,7 +821,15 @@ static int verify_ima(const char *file) if (sigfile) { void *tmp = file2bin(file, "sig", &len); - assert(len <= sizeof(sig)); + if (!tmp) { + log_err("Failed reading: %s\n", file); + return -1; + } + if (len > sizeof(sig)) { + log_err("Signature file is too big: %s\n", file); + free(tmp); + return -1; + } memcpy(sig, tmp, len); free(tmp); } else {