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:
Bart Van Assche
2019-11-03 14:59:11 -08:00
parent 10599fcd4f
commit cc3ddbff42
10 changed files with 19 additions and 52 deletions

View File

@@ -27,7 +27,6 @@
static int new_tl;
static struct iscsi_transport iscsi_drv_orig;
static int my_iscsi_queue_pdu(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
{
@@ -45,7 +44,7 @@ static int my_iscsi_queue_pdu(struct iscsi_context *iscsi, struct iscsi_pdu *pdu
break;
}
out:
return iscsi_drv_orig.queue_pdu(iscsi, pdu);
return orig_queue_pdu(iscsi, pdu);
}
void
@@ -58,7 +57,6 @@ test_compareandwrite_invalid_dataout_size(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, LOG_BLANK_LINE);
@@ -86,7 +84,4 @@ test_compareandwrite_invalid_dataout_size(void)
scratch, 4 * block_size,
block_size, 0, 0, 0, 0,
EXPECT_STATUS_GENERIC_BAD);
/* restore transport callbacks */
*(sd->iscsi_ctx->drv) = iscsi_drv_orig;
}