From fc8d655dc692fea1c5e147d7694b26ba962bf5a7 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Mon, 23 Apr 2018 07:11:09 +0200 Subject: [PATCH] src: fix node_crypto.cc compiler warnings Currently the following compiler warnings are issued by clang: ../src/node_crypto.cc:2801:56: warning: '&&' within '||' [-Wlogical-op-parentheses] return tag_len == 4 || tag_len == 8 || tag_len >= 12 && tag_len <= 16; ~~ ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ ../src/node_crypto.cc:2801:56: note: place parentheses around the '&&' expression to silence this warning return tag_len == 4 || tag_len == 8 || tag_len >= 12 && tag_len <= 16; ^ ../src/node_crypto.cc:2925:51: warning: '&&' within '||' [-Wlogical-op-parentheses] if (cipher->auth_tag_len_ != kNoAuthTagLength && ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~ ../src/node_crypto.cc:2925:51: note: place parentheses around the '&&' expression to silence this warning if (cipher->auth_tag_len_ != kNoAuthTagLength && ^ This commit adds parenthesis around these expressions to silence the warnings. --- src/node_crypto.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 255dc6e2d42e64..3e405e2764873b 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -2798,7 +2798,7 @@ void CipherBase::InitIv(const FunctionCallbackInfo& args) { static bool IsValidGCMTagLength(unsigned int tag_len) { - return tag_len == 4 || tag_len == 8 || tag_len >= 12 && tag_len <= 16; + return tag_len == 4 || tag_len == 8 || (tag_len >= 12 && tag_len <= 16); } bool CipherBase::InitAuthenticated(const char *cipher_type, int iv_len, @@ -2922,8 +2922,8 @@ void CipherBase::SetAuthTag(const FunctionCallbackInfo& args) { unsigned int tag_len = Buffer::Length(args[0]); const int mode = EVP_CIPHER_CTX_mode(cipher->ctx_); if (mode == EVP_CIPH_GCM_MODE) { - if (cipher->auth_tag_len_ != kNoAuthTagLength && - cipher->auth_tag_len_ != tag_len || + if ((cipher->auth_tag_len_ != kNoAuthTagLength && + cipher->auth_tag_len_ != tag_len) || !IsValidGCMTagLength(tag_len)) { char msg[50]; snprintf(msg, sizeof(msg),