From c9bae587b980039738486812411a526eff1cc781 Mon Sep 17 00:00:00 2001 From: Aveen Ismail Date: Wed, 4 Sep 2024 14:55:55 +0200 Subject: [PATCH] Calculate lengths instead of using magic numbers --- common/util.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/common/util.c b/common/util.c index 3fc23e7c..a41ac02f 100644 --- a/common/util.c +++ b/common/util.c @@ -70,12 +70,14 @@ bool read_ed25519_key(uint8_t *in, size_t in_len, uint8_t *out, uint8_t decoded[128]; size_t decoded_len = sizeof(decoded); - if(in_len < (sizeof(PEM_private_header) + sizeof(PEM_private_trailer)-3)) { + if (in_len < (sizeof(PEM_private_header) + sizeof(PEM_private_trailer) - + 3)) { // -3 to account for null bytes in PEM_private_header and + // PEM_private_trailer return false; } - if (memcmp(in, PEM_private_header, sizeof(PEM_private_header)-1) != 0 || - memcmp(in + in_len - sizeof(PEM_private_header), PEM_private_trailer, - sizeof(PEM_private_header) - 2) != 0) { + if (memcmp(in, PEM_private_header, sizeof(PEM_private_header) - 1) != 0 || + memcmp(in + in_len - (sizeof(PEM_private_trailer) - 1), + PEM_private_trailer, sizeof(PEM_private_trailer) - 2) != 0) { return false; } @@ -107,7 +109,7 @@ bool read_ed25519_key(uint8_t *in, size_t in_len, uint8_t *out, BIO_free_all(b64); - if (ret <= 0 || ret != 48) { + if (ret != 48) { return false; }