test-tool: Avoid crashes due to NULL-pointer dereferences
Avoid that certain test failures cause the test tool to trigger a segmentation fault. Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
This commit is contained in:
@@ -69,6 +69,10 @@ test_extendedcopy_descr_limits(void)
|
||||
RECEIVE_COPY_RESULTS(&edl_task, sd, SCSI_COPY_RESULTS_OP_PARAMS, 0,
|
||||
(void **)&opp, EXPECT_STATUS_GOOD);
|
||||
|
||||
CU_ASSERT_NOT_EQUAL(opp, NULL);
|
||||
if (!opp)
|
||||
return;
|
||||
|
||||
/* Allocate buffer to accommodate (MAX+1) target and
|
||||
* segment descriptors */
|
||||
alloc_len = XCOPY_DESC_OFFSET +
|
||||
|
||||
@@ -51,7 +51,7 @@ test_prin_report_caps_simple(void)
|
||||
int ret = 0;
|
||||
const unsigned long long key = rand_key();
|
||||
struct scsi_task *tsk;
|
||||
struct scsi_persistent_reserve_in_report_capabilities *rcaps;
|
||||
struct scsi_persistent_reserve_in_report_capabilities *rcaps = NULL;
|
||||
struct test_prin_report_caps_types *type;
|
||||
|
||||
CHECK_FOR_DATALOSS;
|
||||
@@ -71,6 +71,10 @@ test_prin_report_caps_simple(void)
|
||||
|
||||
ret = prin_report_caps(sd, &tsk, &rcaps);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
CU_ASSERT_NOT_EQUAL(rcaps, NULL);
|
||||
|
||||
if (!rcaps)
|
||||
return;
|
||||
|
||||
logging(LOG_VERBOSE,
|
||||
"Checking PERSISTENT RESERVE IN REPORT CAPABILITIES fields.");
|
||||
|
||||
@@ -33,7 +33,7 @@ test_prout_clear_simple(void)
|
||||
uint32_t old_gen;
|
||||
const unsigned long long key = rand_key();
|
||||
struct scsi_task *tsk;
|
||||
struct scsi_persistent_reserve_in_read_keys *rk;
|
||||
struct scsi_persistent_reserve_in_read_keys *rk = NULL;
|
||||
|
||||
CHECK_FOR_DATALOSS;
|
||||
|
||||
@@ -51,6 +51,9 @@ test_prout_clear_simple(void)
|
||||
|
||||
ret = prin_read_keys(sd, &tsk, &rk);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
CU_ASSERT_NOT_EQUAL(rk, NULL);
|
||||
if (!rk)
|
||||
goto out;
|
||||
|
||||
CU_ASSERT_NOT_EQUAL(rk->num_keys, 0);
|
||||
/* retain PR generation number to check for increments */
|
||||
@@ -78,11 +81,15 @@ test_prout_clear_simple(void)
|
||||
|
||||
ret = prin_read_keys(sd, &tsk, &rk);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
CU_ASSERT_NOT_EQUAL(rk, NULL);
|
||||
if (!rk)
|
||||
goto out;
|
||||
|
||||
CU_ASSERT_EQUAL(rk->num_keys, 0);
|
||||
/* generation incremented once for CLEAR (not for RESERVE) */
|
||||
CU_ASSERT_EQUAL(rk->prgeneration, old_gen + 1);
|
||||
|
||||
out:
|
||||
scsi_free_scsi_task(tsk);
|
||||
rk = NULL; /* freed with tsk */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user