From 3e2f8870a3d10dee41e793e870b6154287ab4263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konrad=20Go=C5=82awski?= Date: Wed, 14 Sep 2022 01:00:20 +0200 Subject: [PATCH] Fix improper strings comparision --- src/modules/module_29511.c | 11 ++++++----- src/modules/module_29512.c | 11 ++++++----- src/modules/module_29513.c | 11 ++++++----- src/modules/module_29521.c | 11 ++++++----- src/modules/module_29522.c | 11 ++++++----- src/modules/module_29523.c | 11 ++++++----- src/modules/module_29531.c | 11 ++++++----- src/modules/module_29532.c | 11 ++++++----- src/modules/module_29533.c | 11 ++++++----- src/modules/module_29541.c | 11 ++++++----- src/modules/module_29542.c | 11 ++++++----- src/modules/module_29543.c | 11 ++++++----- 12 files changed, 72 insertions(+), 60 deletions(-) diff --git a/src/modules/module_29511.c b/src/modules/module_29511.c index 2ef84fc3f..e2b098ba7 100644 --- a/src/modules/module_29511.c +++ b/src/modules/module_29511.c @@ -217,24 +217,25 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // cipher mode const u8 *cipher_mode_pos = token.buf[1]; + const u32 cipher_mode_len = token.len[1]; - if (strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) + if ((strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) && (cipher_mode_len == 16)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_ESSIV_SHA256; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN64; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN64; } diff --git a/src/modules/module_29512.c b/src/modules/module_29512.c index f64387cb3..8db821145 100644 --- a/src/modules/module_29512.c +++ b/src/modules/module_29512.c @@ -217,24 +217,25 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // cipher mode const u8 *cipher_mode_pos = token.buf[1]; + const u32 cipher_mode_len = token.len[1]; - if (strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) + if ((strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) && (cipher_mode_len == 16)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_ESSIV_SHA256; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN64; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN64; } diff --git a/src/modules/module_29513.c b/src/modules/module_29513.c index 197bcc101..61e6c6a46 100644 --- a/src/modules/module_29513.c +++ b/src/modules/module_29513.c @@ -217,24 +217,25 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // cipher mode const u8 *cipher_mode_pos = token.buf[1]; + const u32 cipher_mode_len = token.len[1]; - if (strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) + if ((strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) && (cipher_mode_len == 16)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_ESSIV_SHA256; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN64; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN64; } diff --git a/src/modules/module_29521.c b/src/modules/module_29521.c index 73a22ac77..5a1bb3320 100644 --- a/src/modules/module_29521.c +++ b/src/modules/module_29521.c @@ -217,24 +217,25 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // cipher mode const u8 *cipher_mode_pos = token.buf[1]; + const u32 cipher_mode_len = token.len[1]; - if (strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) + if ((strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) && (cipher_mode_len == 16)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_ESSIV_SHA256; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN64; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN64; } diff --git a/src/modules/module_29522.c b/src/modules/module_29522.c index 5b8328e59..e424d3c66 100644 --- a/src/modules/module_29522.c +++ b/src/modules/module_29522.c @@ -217,24 +217,25 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // cipher mode const u8 *cipher_mode_pos = token.buf[1]; + const u32 cipher_mode_len = token.len[1]; - if (strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) + if ((strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) && (cipher_mode_len == 16)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_ESSIV_SHA256; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN64; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN64; } diff --git a/src/modules/module_29523.c b/src/modules/module_29523.c index 649d3dd85..0a6a7705b 100644 --- a/src/modules/module_29523.c +++ b/src/modules/module_29523.c @@ -217,24 +217,25 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // cipher mode const u8 *cipher_mode_pos = token.buf[1]; + const u32 cipher_mode_len = token.len[1]; - if (strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) + if ((strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) && (cipher_mode_len == 16)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_ESSIV_SHA256; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN64; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN64; } diff --git a/src/modules/module_29531.c b/src/modules/module_29531.c index 43606f79f..2fd82133e 100644 --- a/src/modules/module_29531.c +++ b/src/modules/module_29531.c @@ -217,24 +217,25 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // cipher mode const u8 *cipher_mode_pos = token.buf[1]; + const u32 cipher_mode_len = token.len[1]; - if (strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) + if ((strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) && (cipher_mode_len == 16)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_ESSIV_SHA256; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN64; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN64; } diff --git a/src/modules/module_29532.c b/src/modules/module_29532.c index 5347172ff..3ebdb3fcb 100644 --- a/src/modules/module_29532.c +++ b/src/modules/module_29532.c @@ -217,24 +217,25 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // cipher mode const u8 *cipher_mode_pos = token.buf[1]; + const u32 cipher_mode_len = token.len[1]; - if (strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) + if ((strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) && (cipher_mode_len == 16)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_ESSIV_SHA256; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN64; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN64; } diff --git a/src/modules/module_29533.c b/src/modules/module_29533.c index 635928401..ef52bafba 100644 --- a/src/modules/module_29533.c +++ b/src/modules/module_29533.c @@ -217,24 +217,25 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // cipher mode const u8 *cipher_mode_pos = token.buf[1]; + const u32 cipher_mode_len = token.len[1]; - if (strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) + if ((strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) && (cipher_mode_len == 16)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_ESSIV_SHA256; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN64; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN64; } diff --git a/src/modules/module_29541.c b/src/modules/module_29541.c index caa788811..9bab26aed 100644 --- a/src/modules/module_29541.c +++ b/src/modules/module_29541.c @@ -217,24 +217,25 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // cipher mode const u8 *cipher_mode_pos = token.buf[1]; + const u32 cipher_mode_len = token.len[1]; - if (strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) + if ((strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) && (cipher_mode_len == 16)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_ESSIV_SHA256; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN64; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN64; } diff --git a/src/modules/module_29542.c b/src/modules/module_29542.c index b38ecf45a..08bf7e871 100644 --- a/src/modules/module_29542.c +++ b/src/modules/module_29542.c @@ -217,24 +217,25 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // cipher mode const u8 *cipher_mode_pos = token.buf[1]; + const u32 cipher_mode_len = token.len[1]; - if (strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) + if ((strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) && (cipher_mode_len == 16)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_ESSIV_SHA256; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN64; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN64; } diff --git a/src/modules/module_29543.c b/src/modules/module_29543.c index fb7528877..9c77dacc5 100644 --- a/src/modules/module_29543.c +++ b/src/modules/module_29543.c @@ -217,24 +217,25 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE // cipher mode const u8 *cipher_mode_pos = token.buf[1]; + const u32 cipher_mode_len = token.len[1]; - if (strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) + if ((strncmp ((const char *) cipher_mode_pos, "cbc-essiv:sha256", 16) == 0) && (cipher_mode_len == 16)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_ESSIV_SHA256; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "cbc-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_CBC_PLAIN64; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain", 9) == 0) && (cipher_mode_len == 9)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN; } - else if (strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) + else if ((strncmp ((const char *) cipher_mode_pos, "xts-plain64", 11) == 0) && (cipher_mode_len == 11)) { luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN64; }