Re: [PATCH ima-evm-utils 1/4] Don't ignore number of items read

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 9/14/22 10:22, Mimi Zohar wrote:
fread() either returns the number of bytes read or the number of items
of data read.  Check that it returns the requested number of items read.

Signed-off-by: Mimi Zohar <zohar@xxxxxxxxxxxxx>
---
  src/evmctl.c | 12 +++++++-----
  1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/evmctl.c b/src/evmctl.c
index 2e21da67c444..bcf724c828f7 100644
--- a/src/evmctl.c
+++ b/src/evmctl.c
@@ -2161,7 +2161,7 @@ static int ima_measurement(const char *file)
  		}
memset(entry.name, 0x00, sizeof(entry.name));
-		if (!fread(entry.name, entry.header.name_len, 1, fp)) {
+		if (fread(entry.name, entry.header.name_len, 1, fp) != 1) {
  			log_err("Unable to read template name\n");
  			goto out;
  		}
@@ -2184,8 +2184,8 @@ static int ima_measurement(const char *file)
/* The "ima" template data is not length prefixed. Skip it. */
  		if (!is_ima_template) {
-			if (!fread(&entry.template_len,
-				   sizeof(entry.template_len), 1, fp)) {
+			if (fread(&entry.template_len,
+				  sizeof(entry.template_len), 1, fp) != 1) {
  				log_err("Unable to read template length\n");
  				goto out;
  			}
@@ -2205,7 +2205,8 @@ static int ima_measurement(const char *file)
  		}
if (!is_ima_template) {
-			if (!fread(entry.template, entry.template_len, 1, fp)) {
+			if (fread(entry.template, entry.template_len,
+				  1, fp) != 1) {
  				log_errno("Unable to read template\n");
  				goto out;
  			}
@@ -2217,7 +2218,8 @@ static int ima_measurement(const char *file)
  			 * The "ima" template data format is digest,
  			 * filename length, filename.
  			 */
-			if (!fread(entry.template, SHA_DIGEST_LENGTH, 1, fp)) {
+			if (fread(entry.template, SHA_DIGEST_LENGTH,
+				  1, fp) != 1) {
  				log_errno("Unable to read file data hash\n");
  				goto out;
  			}

It was correct before as well ...

Reviewed-by: Stefan Berger <stefanb@xxxxxxxxxxxxx>



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux Kernel]     [Linux Kernel Hardening]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux