From 0995b0aa2b013549245d2887614e9cc2612d941f Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Fri, 10 Apr 2015 17:51:38 +0200 Subject: [PATCH] test_*_dpo*: Fix NULL pointer dereferences Avoid that the DPO / DPOFUA tests triggers a NULL pointer dereference if the MODE SENSE command in these tests fails. Signed-off-by: Bart Van Assche --- test-tool/test_compareandwrite_dpofua.c | 9 +++++---- test-tool/test_orwrite_dpofua.c | 9 +++++---- test-tool/test_read10_dpofua.c | 9 +++++---- test-tool/test_read12_dpofua.c | 9 +++++---- test-tool/test_read16_dpofua.c | 9 +++++---- test-tool/test_verify10_dpo.c | 9 +++++---- test-tool/test_verify12_dpo.c | 9 +++++---- test-tool/test_verify16_dpo.c | 9 +++++---- test-tool/test_write10_dpofua.c | 9 +++++---- test-tool/test_write12_dpofua.c | 9 +++++---- test-tool/test_write16_dpofua.c | 9 +++++---- test-tool/test_writeverify10_dpo.c | 9 +++++---- test-tool/test_writeverify12_dpo.c | 9 +++++---- test-tool/test_writeverify16_dpo.c | 9 +++++---- 14 files changed, 70 insertions(+), 56 deletions(-) diff --git a/test-tool/test_compareandwrite_dpofua.c b/test-tool/test_compareandwrite_dpofua.c index 0adc802..1190b66 100644 --- a/test-tool/test_compareandwrite_dpofua.c +++ b/test-tool/test_compareandwrite_dpofua.c @@ -28,7 +28,7 @@ void test_compareandwrite_dpofua(void) { - int ret, dpofua; + int ret, dpofua, usage_data_dpofua; struct scsi_task *ms_task = NULL; struct scsi_mode_sense *ms; struct scsi_task *rso_task = NULL; @@ -48,7 +48,7 @@ test_compareandwrite_dpofua(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "[SUCCESS] Mode sense returned status GOOD"); ms = scsi_datain_unmarshall(ms_task); - dpofua = !!(ms->device_specific_parameter & 0x10); + dpofua = ms && (ms->device_specific_parameter & 0x10); scsi_free_scsi_task(ms_task); if (dpofua) { @@ -114,14 +114,15 @@ test_compareandwrite_dpofua(void) logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); CU_ASSERT_NOT_EQUAL(rsoc, NULL); + usage_data_dpofua = rsoc ? rsoc->cdb_usage_data[1] & 0x18 : -1; if (dpofua) { logging(LOG_VERBOSE, "DPOFUA is set. Verify the DPO/FUA flags " "are set in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x18, 0x18); + CU_ASSERT_EQUAL(usage_data_dpofua, 0x18); } else { logging(LOG_VERBOSE, "DPOFUA is clear. Verify the DPO/FUA " "flags are clear in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x18, 0x00); + CU_ASSERT_EQUAL(usage_data_dpofua, 0x00); } scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_orwrite_dpofua.c b/test-tool/test_orwrite_dpofua.c index 901d143..6e71f74 100644 --- a/test-tool/test_orwrite_dpofua.c +++ b/test-tool/test_orwrite_dpofua.c @@ -28,7 +28,7 @@ void test_orwrite_dpofua(void) { - int ret, dpofua; + int ret, dpofua, usage_data_dpofua; struct scsi_task *ms_task = NULL; struct scsi_mode_sense *ms; struct scsi_task *rso_task = NULL; @@ -48,7 +48,7 @@ test_orwrite_dpofua(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "[SUCCESS] Mode sense returned status GOOD"); ms = scsi_datain_unmarshall(ms_task); - dpofua = !!(ms->device_specific_parameter & 0x10); + dpofua = ms && (ms->device_specific_parameter & 0x10); scsi_free_scsi_task(ms_task); if (dpofua) { @@ -124,14 +124,15 @@ test_orwrite_dpofua(void) logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); CU_ASSERT_NOT_EQUAL(rsoc, NULL); + usage_data_dpofua = rsoc ? rsoc->cdb_usage_data[1] & 0x18 : -1; if (dpofua) { logging(LOG_VERBOSE, "DPOFUA is set. Verify the DPO/FUA flags " "are set in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x18, 0x18); + CU_ASSERT_EQUAL(usage_data_dpofua, 0x18); } else { logging(LOG_VERBOSE, "DPOFUA is clear. Verify the DPO/FUA " "flags are clear in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x18, 0x00); + CU_ASSERT_EQUAL(usage_data_dpofua, 0x00); } scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_read10_dpofua.c b/test-tool/test_read10_dpofua.c index 8c005e0..5f3b9e2 100644 --- a/test-tool/test_read10_dpofua.c +++ b/test-tool/test_read10_dpofua.c @@ -28,7 +28,7 @@ void test_read10_dpofua(void) { - int ret, dpofua; + int ret, dpofua, usage_data_dpofua; struct scsi_task *ms_task = NULL; struct scsi_mode_sense *ms; struct scsi_task *rso_task = NULL; @@ -46,7 +46,7 @@ test_read10_dpofua(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "[SUCCESS] Mode sense returned status GOOD"); ms = scsi_datain_unmarshall(ms_task); - dpofua = !!(ms->device_specific_parameter & 0x10); + dpofua = ms && (ms->device_specific_parameter & 0x10); scsi_free_scsi_task(ms_task); if (dpofua) { @@ -113,14 +113,15 @@ test_read10_dpofua(void) logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); CU_ASSERT_NOT_EQUAL(rsoc, NULL); + usage_data_dpofua = rsoc ? rsoc->cdb_usage_data[1] & 0x18 : -1; if (dpofua) { logging(LOG_VERBOSE, "DPOFUA is set. Verify the DPO/FUA flags " "are set in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x18, 0x18); + CU_ASSERT_EQUAL(usage_data_dpofua, 0x18); } else { logging(LOG_VERBOSE, "DPOFUA is clear. Verify the DPO/FUA " "flags are clear in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x18, 0x00); + CU_ASSERT_EQUAL(usage_data_dpofua, 0x00); } scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_read12_dpofua.c b/test-tool/test_read12_dpofua.c index d964061..22d7658 100644 --- a/test-tool/test_read12_dpofua.c +++ b/test-tool/test_read12_dpofua.c @@ -28,7 +28,7 @@ void test_read12_dpofua(void) { - int ret, dpofua; + int ret, dpofua, usage_data_dpofua; struct scsi_task *ms_task = NULL; struct scsi_mode_sense *ms; struct scsi_task *rso_task = NULL; @@ -46,7 +46,7 @@ test_read12_dpofua(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "[SUCCESS] Mode sense returned status GOOD"); ms = scsi_datain_unmarshall(ms_task); - dpofua = !!(ms->device_specific_parameter & 0x10); + dpofua = ms && (ms->device_specific_parameter & 0x10); scsi_free_scsi_task(ms_task); if (dpofua) { @@ -112,14 +112,15 @@ test_read12_dpofua(void) logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); CU_ASSERT_NOT_EQUAL(rsoc, NULL); + usage_data_dpofua = rsoc ? rsoc->cdb_usage_data[1] & 0x18 : -1; if (dpofua) { logging(LOG_VERBOSE, "DPOFUA is set. Verify the DPO/FUA flags " "are set in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x18, 0x18); + CU_ASSERT_EQUAL(usage_data_dpofua, 0x18); } else { logging(LOG_VERBOSE, "DPOFUA is clear. Verify the DPO/FUA " "flags are clear in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x18, 0x00); + CU_ASSERT_EQUAL(usage_data_dpofua, 0x00); } scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_read16_dpofua.c b/test-tool/test_read16_dpofua.c index 906a484..425c6f4 100644 --- a/test-tool/test_read16_dpofua.c +++ b/test-tool/test_read16_dpofua.c @@ -28,7 +28,7 @@ void test_read16_dpofua(void) { - int ret, dpofua; + int ret, dpofua, usage_data_dpofua; struct scsi_task *ms_task = NULL; struct scsi_mode_sense *ms; struct scsi_task *rso_task = NULL; @@ -46,7 +46,7 @@ test_read16_dpofua(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "[SUCCESS] Mode sense returned status GOOD"); ms = scsi_datain_unmarshall(ms_task); - dpofua = !!(ms->device_specific_parameter & 0x10); + dpofua = ms && (ms->device_specific_parameter & 0x10); scsi_free_scsi_task(ms_task); if (dpofua) { @@ -113,14 +113,15 @@ test_read16_dpofua(void) logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); CU_ASSERT_NOT_EQUAL(rsoc, NULL); + usage_data_dpofua = rsoc ? rsoc->cdb_usage_data[1] & 0x18 : -1; if (dpofua) { logging(LOG_VERBOSE, "DPOFUA is set. Verify the DPO/FUA flags " "are set in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x18, 0x18); + CU_ASSERT_EQUAL(usage_data_dpofua, 0x18); } else { logging(LOG_VERBOSE, "DPOFUA is clear. Verify the DPO/FUA " "flags are clear in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x18, 0x00); + CU_ASSERT_EQUAL(usage_data_dpofua, 0x00); } scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_verify10_dpo.c b/test-tool/test_verify10_dpo.c index 39d9aaa..9f7abe4 100644 --- a/test-tool/test_verify10_dpo.c +++ b/test-tool/test_verify10_dpo.c @@ -28,7 +28,7 @@ void test_verify10_dpo(void) { - int ret, dpofua; + int ret, dpofua, usage_data_dpo; struct scsi_task *ms_task = NULL; struct scsi_mode_sense *ms; struct scsi_task *rso_task = NULL; @@ -52,7 +52,7 @@ test_verify10_dpo(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "[SUCCESS] Mode sense returned status GOOD"); ms = scsi_datain_unmarshall(ms_task); - dpofua = !!(ms->device_specific_parameter & 0x10); + dpofua = ms && (ms->device_specific_parameter & 0x10); scsi_free_scsi_task(ms_task); if (dpofua) { @@ -102,14 +102,15 @@ test_verify10_dpo(void) logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); CU_ASSERT_NOT_EQUAL(rsoc, NULL); + usage_data_dpo = rsoc ? rsoc->cdb_usage_data[1] & 0x10 : -1; if (dpofua) { logging(LOG_VERBOSE, "DPOFUA is set. Verify the DPO flag " "is set in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x10, 0x10); + CU_ASSERT_EQUAL(usage_data_dpo, 0x10); } else { logging(LOG_VERBOSE, "DPOFUA is clear. Verify the DPO " "flag is clear in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x10, 0x00); + CU_ASSERT_EQUAL(usage_data_dpo, 0x00); } scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_verify12_dpo.c b/test-tool/test_verify12_dpo.c index b8f5296..f3976d2 100644 --- a/test-tool/test_verify12_dpo.c +++ b/test-tool/test_verify12_dpo.c @@ -28,7 +28,7 @@ void test_verify12_dpo(void) { - int ret, dpofua; + int ret, dpofua, usage_data_dpo; struct scsi_task *ms_task = NULL; struct scsi_mode_sense *ms; struct scsi_task *rso_task = NULL; @@ -52,7 +52,7 @@ test_verify12_dpo(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "[SUCCESS] Mode sense returned status GOOD"); ms = scsi_datain_unmarshall(ms_task); - dpofua = !!(ms->device_specific_parameter & 0x10); + dpofua = ms && (ms->device_specific_parameter & 0x10); scsi_free_scsi_task(ms_task); if (dpofua) { @@ -102,14 +102,15 @@ test_verify12_dpo(void) logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); CU_ASSERT_NOT_EQUAL(rsoc, NULL); + usage_data_dpo = rsoc ? rsoc->cdb_usage_data[1] & 0x10 : -1; if (dpofua) { logging(LOG_VERBOSE, "DPOFUA is set. Verify the DPO flag " "is set in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x10, 0x10); + CU_ASSERT_EQUAL(usage_data_dpo, 0x10); } else { logging(LOG_VERBOSE, "DPOFUA is clear. Verify the DPO " "flag is clear in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x10, 0x00); + CU_ASSERT_EQUAL(usage_data_dpo, 0x00); } scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_verify16_dpo.c b/test-tool/test_verify16_dpo.c index 9e68830..66b9d32 100644 --- a/test-tool/test_verify16_dpo.c +++ b/test-tool/test_verify16_dpo.c @@ -28,7 +28,7 @@ void test_verify16_dpo(void) { - int ret, dpofua; + int ret, dpofua, usage_data_dpo; struct scsi_task *ms_task = NULL; struct scsi_mode_sense *ms; struct scsi_task *rso_task = NULL; @@ -52,7 +52,7 @@ test_verify16_dpo(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "[SUCCESS] Mode sense returned status GOOD"); ms = scsi_datain_unmarshall(ms_task); - dpofua = !!(ms->device_specific_parameter & 0x10); + dpofua = ms && (ms->device_specific_parameter & 0x10); scsi_free_scsi_task(ms_task); if (dpofua) { @@ -102,14 +102,15 @@ test_verify16_dpo(void) logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); CU_ASSERT_NOT_EQUAL(rsoc, NULL); + usage_data_dpo = rsoc ? rsoc->cdb_usage_data[1] & 0x10 : -1; if (dpofua) { logging(LOG_VERBOSE, "DPOFUA is set. Verify the DPO flag " "is set in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x10, 0x10); + CU_ASSERT_EQUAL(usage_data_dpo, 0x10); } else { logging(LOG_VERBOSE, "DPOFUA is clear. Verify the DPO " "flag is clear in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x10, 0x00); + CU_ASSERT_EQUAL(usage_data_dpo, 0x00); } scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_write10_dpofua.c b/test-tool/test_write10_dpofua.c index 3eac700..9f5e55c 100644 --- a/test-tool/test_write10_dpofua.c +++ b/test-tool/test_write10_dpofua.c @@ -28,7 +28,7 @@ void test_write10_dpofua(void) { - int ret, dpofua; + int ret, dpofua, usage_data_dpofua; struct scsi_task *ms_task = NULL; struct scsi_mode_sense *ms; struct scsi_task *rso_task = NULL; @@ -48,7 +48,7 @@ test_write10_dpofua(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "[SUCCESS] Mode sense returned status GOOD"); ms = scsi_datain_unmarshall(ms_task); - dpofua = !!(ms->device_specific_parameter & 0x10); + dpofua = ms && (ms->device_specific_parameter & 0x10); scsi_free_scsi_task(ms_task); if (dpofua) { @@ -115,14 +115,15 @@ test_write10_dpofua(void) logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); CU_ASSERT_NOT_EQUAL(rsoc, NULL); + usage_data_dpofua = rsoc ? rsoc->cdb_usage_data[1] & 0x18 : -1; if (dpofua) { logging(LOG_VERBOSE, "DPOFUA is set. Verify the DPO/FUA flags " "are set in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x18, 0x18); + CU_ASSERT_EQUAL(usage_data_dpofua, 0x18); } else { logging(LOG_VERBOSE, "DPOFUA is clear. Verify the DPO/FUA " "flags are clear in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x18, 0x00); + CU_ASSERT_EQUAL(usage_data_dpofua, 0x00); } scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_write12_dpofua.c b/test-tool/test_write12_dpofua.c index 15ea187..dd20a4d 100644 --- a/test-tool/test_write12_dpofua.c +++ b/test-tool/test_write12_dpofua.c @@ -28,7 +28,7 @@ void test_write12_dpofua(void) { - int ret, dpofua; + int ret, dpofua, usage_data_dpofua; struct scsi_task *ms_task = NULL; struct scsi_mode_sense *ms; struct scsi_task *rso_task = NULL; @@ -48,7 +48,7 @@ test_write12_dpofua(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "[SUCCESS] Mode sense returned status GOOD"); ms = scsi_datain_unmarshall(ms_task); - dpofua = !!(ms->device_specific_parameter & 0x10); + dpofua = ms && (ms->device_specific_parameter & 0x10); scsi_free_scsi_task(ms_task); if (dpofua) { @@ -125,14 +125,15 @@ test_write12_dpofua(void) logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); CU_ASSERT_NOT_EQUAL(rsoc, NULL); + usage_data_dpofua = rsoc ? rsoc->cdb_usage_data[1] & 0x18 : -1; if (dpofua) { logging(LOG_VERBOSE, "DPOFUA is set. Verify the DPO/FUA flags " "are set in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x18, 0x18); + CU_ASSERT_EQUAL(usage_data_dpofua, 0x18); } else { logging(LOG_VERBOSE, "DPOFUA is clear. Verify the DPO/FUA " "flags are clear in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x18, 0x00); + CU_ASSERT_EQUAL(usage_data_dpofua, 0x00); } scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_write16_dpofua.c b/test-tool/test_write16_dpofua.c index 396e253..c3f0e85 100644 --- a/test-tool/test_write16_dpofua.c +++ b/test-tool/test_write16_dpofua.c @@ -28,7 +28,7 @@ void test_write16_dpofua(void) { - int ret, dpofua; + int ret, dpofua, usage_data_dpofua; struct scsi_task *ms_task = NULL; struct scsi_mode_sense *ms; struct scsi_task *rso_task = NULL; @@ -48,7 +48,7 @@ test_write16_dpofua(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "[SUCCESS] Mode sense returned status GOOD"); ms = scsi_datain_unmarshall(ms_task); - dpofua = !!(ms->device_specific_parameter & 0x10); + dpofua = ms && (ms->device_specific_parameter & 0x10); scsi_free_scsi_task(ms_task); if (dpofua) { @@ -125,14 +125,15 @@ test_write16_dpofua(void) logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); CU_ASSERT_NOT_EQUAL(rsoc, NULL); + usage_data_dpofua = rsoc ? rsoc->cdb_usage_data[1] & 0x18 : -1; if (dpofua) { logging(LOG_VERBOSE, "DPOFUA is set. Verify the DPO/FUA flags " "are set in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x18, 0x18); + CU_ASSERT_EQUAL(usage_data_dpofua, 0x18); } else { logging(LOG_VERBOSE, "DPOFUA is clear. Verify the DPO/FUA " "flags are clear in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x18, 0x00); + CU_ASSERT_EQUAL(usage_data_dpofua, 0x00); } scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_writeverify10_dpo.c b/test-tool/test_writeverify10_dpo.c index eb2a140..1c30e4d 100644 --- a/test-tool/test_writeverify10_dpo.c +++ b/test-tool/test_writeverify10_dpo.c @@ -28,7 +28,7 @@ void test_writeverify10_dpo(void) { - int ret, dpofua; + int ret, dpofua, usage_data_dpo; struct scsi_task *ms_task = NULL; struct scsi_mode_sense *ms; struct scsi_task *rso_task = NULL; @@ -52,7 +52,7 @@ test_writeverify10_dpo(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "[SUCCESS] Mode sense returned status GOOD"); ms = scsi_datain_unmarshall(ms_task); - dpofua = !!(ms->device_specific_parameter & 0x10); + dpofua = ms && (ms->device_specific_parameter & 0x10); scsi_free_scsi_task(ms_task); if (dpofua) { @@ -102,14 +102,15 @@ test_writeverify10_dpo(void) logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); CU_ASSERT_NOT_EQUAL(rsoc, NULL); + usage_data_dpo = rsoc ? rsoc->cdb_usage_data[1] & 0x10 : -1; if (dpofua) { logging(LOG_VERBOSE, "DPOFUA is set. Verify the DPO flag " "is set in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x10, 0x10); + CU_ASSERT_EQUAL(usage_data_dpo, 0x10); } else { logging(LOG_VERBOSE, "DPOFUA is clear. Verify the DPO " "flag is clear in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x10, 0x00); + CU_ASSERT_EQUAL(usage_data_dpo, 0x00); } scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_writeverify12_dpo.c b/test-tool/test_writeverify12_dpo.c index bc3a7b1..068d516 100644 --- a/test-tool/test_writeverify12_dpo.c +++ b/test-tool/test_writeverify12_dpo.c @@ -28,7 +28,7 @@ void test_writeverify12_dpo(void) { - int ret, dpofua; + int ret, dpofua, usage_data_dpo; struct scsi_task *ms_task = NULL; struct scsi_mode_sense *ms; struct scsi_task *rso_task = NULL; @@ -52,7 +52,7 @@ test_writeverify12_dpo(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "[SUCCESS] Mode sense returned status GOOD"); ms = scsi_datain_unmarshall(ms_task); - dpofua = !!(ms->device_specific_parameter & 0x10); + dpofua = ms && (ms->device_specific_parameter & 0x10); scsi_free_scsi_task(ms_task); if (dpofua) { @@ -102,14 +102,15 @@ test_writeverify12_dpo(void) logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); CU_ASSERT_NOT_EQUAL(rsoc, NULL); + usage_data_dpo = rsoc ? rsoc->cdb_usage_data[1] & 0x10 : -1; if (dpofua) { logging(LOG_VERBOSE, "DPOFUA is set. Verify the DPO flag " "is set in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x10, 0x10); + CU_ASSERT_EQUAL(usage_data_dpo, 0x10); } else { logging(LOG_VERBOSE, "DPOFUA is clear. Verify the DPO " "flag is clear in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x10, 0x00); + CU_ASSERT_EQUAL(usage_data_dpo, 0x00); } scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_writeverify16_dpo.c b/test-tool/test_writeverify16_dpo.c index b439f2b..14c43ba 100644 --- a/test-tool/test_writeverify16_dpo.c +++ b/test-tool/test_writeverify16_dpo.c @@ -28,7 +28,7 @@ void test_writeverify16_dpo(void) { - int ret, dpofua; + int ret, dpofua, usage_data_dpo; struct scsi_task *ms_task = NULL; struct scsi_mode_sense *ms; struct scsi_task *rso_task = NULL; @@ -52,7 +52,7 @@ test_writeverify16_dpo(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "[SUCCESS] Mode sense returned status GOOD"); ms = scsi_datain_unmarshall(ms_task); - dpofua = !!(ms->device_specific_parameter & 0x10); + dpofua = ms && (ms->device_specific_parameter & 0x10); scsi_free_scsi_task(ms_task); if (dpofua) { @@ -103,14 +103,15 @@ test_writeverify16_dpo(void) logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); CU_ASSERT_NOT_EQUAL(rsoc, NULL); + usage_data_dpo = rsoc ? rsoc->cdb_usage_data[1] & 0x10 : -1; if (dpofua) { logging(LOG_VERBOSE, "DPOFUA is set. Verify the DPO flag " "is set in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x10, 0x10); + CU_ASSERT_EQUAL(usage_data_dpo, 0x10); } else { logging(LOG_VERBOSE, "DPOFUA is clear. Verify the DPO " "flag is clear in the CDB_USAGE_DATA"); - CU_ASSERT_EQUAL(rsoc->cdb_usage_data[1] & 0x10, 0x00); + CU_ASSERT_EQUAL(usage_data_dpo, 0x00); } scsi_free_scsi_task(rso_task); }