From 02d5b18ef7e3a1f1e2c3b31bdce0aaaaf031b1f4 Mon Sep 17 00:00:00 2001 From: Martin Kaiser Date: Sat, 19 Jan 2019 19:30:12 +0100 Subject: [PATCH] crypto1_create: initialize malloc()ed memory to 0 On systems that support malloc(), crypto1_create() allocates a new struct Crypto1State and starts calculations without initializing the allocated memory area. At least on Linux, malloc(3) says that the allocated memory is not initialized. Looking at the version for bare metal ARM, it seems that the components of struct Crypto1State should be 0 initially. Add a memset() call to initialize them. --- common/crapto1/crypto1.c | 1 + 1 file changed, 1 insertion(+) diff --git a/common/crapto1/crypto1.c b/common/crapto1/crypto1.c index 19b71cbb..716410b6 100644 --- a/common/crapto1/crypto1.c +++ b/common/crapto1/crypto1.c @@ -47,6 +47,7 @@ struct Crypto1State * crypto1_create(uint64_t key) struct Crypto1State *s = malloc(sizeof(*s)); int i; + memset(s, 0x0, sizeof(*s)); for(i = 47;s && i > 0; i -= 2) { s->odd = s->odd << 1 | BIT(key, (i - 1) ^ 7); s->even = s->even << 1 | BIT(key, i ^ 7);