intel / intel-ipsec-mb

Intel(R) Multi-Buffer Crypto for IPSec
BSD 3-Clause "New" or "Revised" License
288 stars 87 forks source link

potential logical error in if statements #79

Closed ColinIanKing closed 3 years ago

ColinIanKing commented 3 years ago

Static analysis picked up some potential logic errors in some if statements in test/api_test.c

713                                /* skip disallowed combos */
714                                if ((hash == IMB_AUTH_CHACHA20_POLY1305 &&
715                                     cipher != IMB_CIPHER_CHACHA20_POLY1305) ||
   CID 113796 (#2 of 3): Operands don't affect result (CONSTANT_EXPRESSION_RESULT)
   result_independent_of_operands: hash != IMB_AUTH_CHACHA20_POLY1305 && 0 /* cipher == IMB_CIPHER_CHACHA20_POLY1305 */ is always false regardless of the values of its operands. This occurs as the logical second operand of "||".
716                                    (hash != IMB_AUTH_CHACHA20_POLY1305 &&
717                                     cipher == IMB_CIPHER_CHACHA20_POLY1305))
718                                        continue;

and

720                                if ((hash == IMB_AUTH_CHACHA20_POLY1305_SGL &&
721                                  cipher != IMB_CIPHER_CHACHA20_POLY1305_SGL) ||
   CID 113796 (#3 of 3): Operands don't affect result (CONSTANT_EXPRESSION_RESULT)
   result_independent_of_operands: hash != IMB_AUTH_CHACHA20_POLY1305_SGL && 0 /* cipher == IMB_CIPHER_CHACHA20_POLY1305_SGL */ is always false regardless of the values of its operands. This occurs as the logical second operand of "||".
722                                  (hash != IMB_AUTH_CHACHA20_POLY1305_SGL &&
723                                  cipher == IMB_CIPHER_CHACHA20_POLY1305_SGL))
724                                        continue;
725

and

726                                if ((hash == IMB_AUTH_GCM_SGL &&
727                                  cipher != IMB_CIPHER_GCM_SGL) ||
   CID 113796 (#1 of 3): Operands don't affect result (CONSTANT_EXPRESSION_RESULT)
   result_independent_of_operands: hash != IMB_AUTH_GCM_SGL && 0 /* cipher == IMB_CIPHER_GCM_SGL */ is always false regardless of the values of its operands. This occurs as the logical second operand of "||".
728                                  (hash != IMB_AUTH_GCM_SGL &&
729                                  cipher == IMB_CIPHER_GCM_SGL))
730                                        continue;