From 676afd07a0d523635f423af35dccfb6c6ab5c883 Mon Sep 17 00:00:00 2001 From: lishiao144 <1447175116@qq.com> Date: Thu, 29 May 2025 11:50:20 +0800 Subject: [PATCH 1/3] Signed vs. unsigned byte mismatch in CHAP_R comparison --- include/iscsi-private.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/iscsi-private.h b/include/iscsi-private.h index 69781ef..1fce36a 100644 --- a/include/iscsi-private.h +++ b/include/iscsi-private.h @@ -124,7 +124,7 @@ struct iscsi_context { char target_user[MAX_STRING_SIZE+1]; char target_passwd[MAX_STRING_SIZE+1]; int target_chap_i; - char target_chap_r[MAX_CHAP_R_SIZE]; + unsigned char target_chap_r[MAX_CHAP_R_SIZE]; char error_string[MAX_STRING_SIZE+1]; From a57f51708c166b51f5b7e195c31cec5d99162e47 Mon Sep 17 00:00:00 2001 From: lishiao144 <1447175116@qq.com> Date: Thu, 29 May 2025 11:51:50 +0800 Subject: [PATCH 2/3] Incorrect handling of CHAP_C encoding during CHAP_R computation --- lib/login.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/login.c b/lib/login.c index 73a6d62..1ff8ae5 100644 --- a/lib/login.c +++ b/lib/login.c @@ -937,7 +937,8 @@ iscsi_login_add_chap_response(struct iscsi_context *iscsi, struct iscsi_pdu *pdu /* bidirectional chap */ if (iscsi->target_user[0]) { char target_chap_c[MAX_CHAP_R_SIZE * 2] = {0}; - + char initiator_chap_c_hex[MAX_CHAP_R_SIZE * 4 + 1] = { 0 }; + iscsi->target_chap_i++; snprintf(str, MAX_STRING_SIZE, "CHAP_I=%d", iscsi->target_chap_i); @@ -962,6 +963,7 @@ iscsi_login_add_chap_response(struct iscsi_context *iscsi, struct iscsi_pdu *pdu c = target_chap_c[i]; cc[0] = i2h((c >> 4)&0x0f); cc[1] = i2h((c )&0x0f); + memcpy(initiator_chap_c_hex + i * 2, cc, 2); if (iscsi_pdu_add_data(iscsi, pdu, &cc[0], 2) != 0) { iscsi_set_error(iscsi, "Out-of-memory: pdu add " "data failed."); @@ -977,7 +979,7 @@ iscsi_login_add_chap_response(struct iscsi_context *iscsi, struct iscsi_pdu *pdu compute_chap_r(iscsi, iscsi->target_chap_i, (unsigned char *)iscsi->target_passwd, - (unsigned char *)target_chap_c, + (unsigned char *)initiator_chap_c_hex, (unsigned char *)iscsi->target_chap_r); } From de86745f143c6356a6cabb9e26db2aa6f1f365bc Mon Sep 17 00:00:00 2001 From: lishiao144 <1447175116@qq.com> Date: Thu, 29 May 2025 14:00:53 +0800 Subject: [PATCH 3/3] Update login.c --- lib/login.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/login.c b/lib/login.c index 1ff8ae5..0dbe3de 100644 --- a/lib/login.c +++ b/lib/login.c @@ -937,7 +937,7 @@ iscsi_login_add_chap_response(struct iscsi_context *iscsi, struct iscsi_pdu *pdu /* bidirectional chap */ if (iscsi->target_user[0]) { char target_chap_c[MAX_CHAP_R_SIZE * 2] = {0}; - char initiator_chap_c_hex[MAX_CHAP_R_SIZE * 4 + 1] = { 0 }; + char target_chap_c_hex[MAX_CHAP_R_SIZE * 4 + 1] = { 0 }; iscsi->target_chap_i++; snprintf(str, MAX_STRING_SIZE, "CHAP_I=%d", @@ -963,7 +963,7 @@ iscsi_login_add_chap_response(struct iscsi_context *iscsi, struct iscsi_pdu *pdu c = target_chap_c[i]; cc[0] = i2h((c >> 4)&0x0f); cc[1] = i2h((c )&0x0f); - memcpy(initiator_chap_c_hex + i * 2, cc, 2); + memcpy(target_chap_c_hex + i * 2, cc, 2); if (iscsi_pdu_add_data(iscsi, pdu, &cc[0], 2) != 0) { iscsi_set_error(iscsi, "Out-of-memory: pdu add " "data failed."); @@ -979,7 +979,7 @@ iscsi_login_add_chap_response(struct iscsi_context *iscsi, struct iscsi_pdu *pdu compute_chap_r(iscsi, iscsi->target_chap_i, (unsigned char *)iscsi->target_passwd, - (unsigned char *)initiator_chap_c_hex, + (unsigned char *)target_chap_c_hex, (unsigned char *)iscsi->target_chap_r); }