public inbox for linux-integrity@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] file2bin: Pass the right values to size and count parameters for fread()
@ 2020-10-19 20:05 Lakshmi Ramasubramanian
  2020-10-19 20:08 ` [ima-evm-utils][PATCH] " Lakshmi Ramasubramanian
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Lakshmi Ramasubramanian @ 2020-10-19 20:05 UTC (permalink / raw)
  To: zohar, pvorel; +Cc: linux-integrity

The 2nd parameter to fread() namely "size" specifies the size, in
bytes of each element to be read, and the 3rd parameter namely "count"
specifies the number of elements, each one with a size of "size" bytes.

 size_t fread ( void * ptr, size_t size, size_t count, FILE * stream );

But in the function file2bin() the values passed to "size" and "count"
are reversed causing the function to return an error eventhough the file
was sucdessfully read.

Pass the right values to "size" and "count" parameters for fread() in
the function file2bin().

Signed-off-by: Lakshmi Ramasubramanian <nramas@linux.microsoft.com>
---
 src/evmctl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/evmctl.c b/src/evmctl.c
index 7ad1150..d49988e 100644
--- a/src/evmctl.c
+++ b/src/evmctl.c
@@ -221,7 +221,8 @@ static unsigned char *file2bin(const char *file, const char *ext, int *size)
 		fclose(fp);
 		return NULL;
 	}
-	if (fread(data, len, 1, fp) != len) {
+
+	if (fread(data, 1, len, fp) != len) {
 		log_err("Failed to fread %zu bytes: %s\n", len, name);
 		fclose(fp);
 		free(data);
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-10-20  6:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-19 20:05 [PATCH] file2bin: Pass the right values to size and count parameters for fread() Lakshmi Ramasubramanian
2020-10-19 20:08 ` [ima-evm-utils][PATCH] " Lakshmi Ramasubramanian
2020-10-19 20:23 ` [PATCH] " Petr Vorel
2020-10-19 22:12 ` Mimi Zohar
2020-10-19 22:22   ` Lakshmi Ramasubramanian
2020-10-19 22:30     ` Mimi Zohar
2020-10-19 22:59       ` Lakshmi Ramasubramanian
2020-10-20  6:53     ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox