From 3b52de7c1c31557093891f8d18d62e2aa0b2ef09 Mon Sep 17 00:00:00 2001 From: Matt Coleman Date: Fri, 14 Feb 2020 11:57:01 -0500 Subject: [PATCH] Simplify logic that determines when to send headers The prior condition could be summarized as: ``` if ((first && second) || second) { ``` This will always evaluate to `second`: ``` ((true && true) || true) == true ((false && true) || true) == true ((true && false) || false) == false ((false && false) || false) == false ``` Reported-by: Jeffrey Knapp --- lib/login.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/login.c b/lib/login.c index c2bf111..73e7673 100644 --- a/lib/login.c +++ b/lib/login.c @@ -54,9 +54,7 @@ iscsi_login_add_initiatorname(struct iscsi_context *iscsi, struct iscsi_pdu *pdu char str[MAX_STRING_SIZE+1]; /* We only send InitiatorName during opneg or the first leg of secneg */ - if ((iscsi->current_phase != ISCSI_PDU_LOGIN_CSG_OPNEG - && iscsi->secneg_phase != ISCSI_LOGIN_SECNEG_PHASE_OFFER_CHAP) - || iscsi->secneg_phase != ISCSI_LOGIN_SECNEG_PHASE_OFFER_CHAP) { + if (iscsi->secneg_phase != ISCSI_LOGIN_SECNEG_PHASE_OFFER_CHAP) { return 0; } @@ -78,9 +76,7 @@ iscsi_login_add_alias(struct iscsi_context *iscsi, struct iscsi_pdu *pdu) char str[MAX_STRING_SIZE+1]; /* We only send InitiatorAlias during opneg or the first leg of secneg */ - if ((iscsi->current_phase != ISCSI_PDU_LOGIN_CSG_OPNEG - && iscsi->secneg_phase != ISCSI_LOGIN_SECNEG_PHASE_OFFER_CHAP) - || iscsi->secneg_phase != ISCSI_LOGIN_SECNEG_PHASE_OFFER_CHAP) { + if (iscsi->secneg_phase != ISCSI_LOGIN_SECNEG_PHASE_OFFER_CHAP) { return 0; } @@ -134,9 +130,7 @@ iscsi_login_add_sessiontype(struct iscsi_context *iscsi, struct iscsi_pdu *pdu) char str[MAX_STRING_SIZE+1]; /* We only send SessionType during opneg or the first leg of secneg */ - if ((iscsi->current_phase != ISCSI_PDU_LOGIN_CSG_OPNEG - && iscsi->secneg_phase != ISCSI_LOGIN_SECNEG_PHASE_OFFER_CHAP) - || iscsi->secneg_phase != ISCSI_LOGIN_SECNEG_PHASE_OFFER_CHAP) { + if (iscsi->secneg_phase != ISCSI_LOGIN_SECNEG_PHASE_OFFER_CHAP) { return 0; }