Improve robustness of the code that restores .queue_pdu()
In my tests I hit a stack overflow caused by infinite recursion of .queue_pdu() calls, caused by .queue_pdu() not being restored in an error path. Make the approach for restoring .queue_pdu() more robust. Signed-off-by: Bart Van Assche <bvanassche@acm.org>
This commit is contained in:
@@ -26,7 +26,6 @@
|
||||
#include "iscsi-test-cu.h"
|
||||
|
||||
static int change_num;
|
||||
static struct iscsi_transport iscsi_drv_orig;
|
||||
|
||||
static int my_iscsi_queue_pdu(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
|
||||
{
|
||||
@@ -46,7 +45,7 @@ static int my_iscsi_queue_pdu(struct iscsi_context *iscsi, struct iscsi_pdu *pdu
|
||||
}
|
||||
|
||||
change_num = 0;
|
||||
return iscsi_drv_orig.queue_pdu(iscsi, pdu);
|
||||
return orig_queue_pdu(iscsi, pdu);
|
||||
}
|
||||
|
||||
void test_sanitize_overwrite_reserved(void)
|
||||
@@ -71,7 +70,6 @@ void test_sanitize_overwrite_reserved(void)
|
||||
CHECK_FOR_ISCSI(sd);
|
||||
|
||||
/* override transport queue_pdu callback for PDU manipulation */
|
||||
iscsi_drv_orig = *sd->iscsi_ctx->drv;
|
||||
sd->iscsi_ctx->drv->queue_pdu = my_iscsi_queue_pdu;
|
||||
|
||||
logging(LOG_VERBOSE, "Send SANITIZE command with the reserved "
|
||||
@@ -88,7 +86,4 @@ void test_sanitize_overwrite_reserved(void)
|
||||
SANITIZE(sd, 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data,
|
||||
EXPECT_INVALID_FIELD_IN_CDB);
|
||||
}
|
||||
|
||||
/* restore transport callbacks */
|
||||
*(sd->iscsi_ctx->drv) = iscsi_drv_orig;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user