[brasero] Fix #597694 - brasero crashed with SIGSEGV in brasero_scsi_command_issue_sync() Fix the few places



commit e62a41950e637c5ae34027c63f2a68f01a59b71a
Author: Philippe Rouquier <bonfire-app wanadoo fr>
Date:   Thu May 20 00:42:44 2010 +0200

    Fix #597694  - brasero crashed with SIGSEGV in brasero_scsi_command_issue_sync()
    Fix the few places where we did not check for the value returned by brasero_device_handle_open () which can be NULL
    Additionally add checks for NULL handle in every function that take one as an argument

 libbrasero-burn/brasero-data-session.c             |   15 +++++++++++++++
 libbrasero-media/burn-volume-source.c              |    2 ++
 libbrasero-media/scsi-get-configuration.c          |    2 ++
 libbrasero-media/scsi-get-performance.c            |    2 ++
 libbrasero-media/scsi-inquiry.c                    |    4 ++++
 libbrasero-media/scsi-mech-status.c                |    2 ++
 libbrasero-media/scsi-mode-select.c                |    2 ++
 libbrasero-media/scsi-mode-sense.c                 |    2 ++
 .../scsi-prevent-allow-medium-removal.c            |    2 ++
 libbrasero-media/scsi-read-capacity.c              |    2 ++
 libbrasero-media/scsi-read-cd.c                    |    2 ++
 libbrasero-media/scsi-read-disc-info.c             |    2 ++
 libbrasero-media/scsi-read-disc-structure.c        |    2 ++
 libbrasero-media/scsi-read-format-capacities.c     |    2 ++
 libbrasero-media/scsi-read-toc-pma-atip.c          |    8 ++++++++
 libbrasero-media/scsi-read-track-information.c     |    2 ++
 libbrasero-media/scsi-read10.c                     |    2 ++
 libbrasero-media/scsi-sg.c                         |    4 ++++
 libbrasero-media/scsi-test-unit-ready.c            |    2 ++
 plugins/checksum/burn-checksum-files.c             |    5 +++++
 20 files changed, 66 insertions(+), 0 deletions(-)
---
diff --git a/libbrasero-burn/brasero-data-session.c b/libbrasero-burn/brasero-data-session.c
index 318d4b0..135fdeb 100644
--- a/libbrasero-burn/brasero-data-session.c
+++ b/libbrasero-burn/brasero-data-session.c
@@ -115,6 +115,21 @@ brasero_io_image_directory_contents_thread (BraseroAsyncTaskManager *manager,
 	BraseroVolSrc *vol;
 
 	handle = brasero_device_handle_open (data->job.uri, FALSE, NULL);
+	if (!handle) {
+		GError *error;
+
+		error = g_error_new (BRASERO_BURN_ERROR,
+		                     BRASERO_BURN_ERROR_GENERAL,
+		                     _("The drive is busy"));
+
+		brasero_io_return_result (data->job.base,
+					  data->job.uri,
+					  NULL,
+					  error,
+					  data->job.callback_data);
+		return BRASERO_ASYNC_TASK_FINISHED;
+	}
+
 	vol = brasero_volume_source_open_device_handle (handle, &error);
 	if (!vol) {
 		brasero_device_handle_close (handle);
diff --git a/libbrasero-media/burn-volume-source.c b/libbrasero-media/burn-volume-source.c
index 42882a0..12a8135 100644
--- a/libbrasero-media/burn-volume-source.c
+++ b/libbrasero-media/burn-volume-source.c
@@ -310,6 +310,8 @@ brasero_volume_source_open_device_handle (BraseroDeviceHandle *handle,
 	BraseroScsiResult result;
 	BraseroScsiGetConfigHdr *hdr = NULL;
 
+	g_return_val_if_fail (handle != NULL, NULL);
+
 	src = g_new0 (BraseroVolSrc, 1);
 	src->ref = 1;
 	src->data = handle;
diff --git a/libbrasero-media/scsi-get-configuration.c b/libbrasero-media/scsi-get-configuration.c
index 17ddfc5..92598b7 100644
--- a/libbrasero-media/scsi-get-configuration.c
+++ b/libbrasero-media/scsi-get-configuration.c
@@ -178,6 +178,7 @@ brasero_mmc2_get_configuration_feature (BraseroDeviceHandle *handle,
 	BraseroScsiResult res;
 	int hdr_size = 0;
 
+	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
 	g_return_val_if_fail (data != NULL, BRASERO_SCSI_FAILURE);
 	g_return_val_if_fail (size != NULL, BRASERO_SCSI_FAILURE);
 
@@ -211,6 +212,7 @@ brasero_mmc2_get_profile (BraseroDeviceHandle *handle,
 	BraseroGetConfigCDB *cdb;
 	BraseroScsiResult res;
 
+	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
 	g_return_val_if_fail (profile != NULL, BRASERO_SCSI_FAILURE);
 
 	cdb = brasero_scsi_command_new (&info, handle);
diff --git a/libbrasero-media/scsi-get-performance.c b/libbrasero-media/scsi-get-performance.c
index d879361..1e53b16 100644
--- a/libbrasero-media/scsi-get-performance.c
+++ b/libbrasero-media/scsi-get-performance.c
@@ -242,6 +242,8 @@ brasero_mmc3_get_performance_wrt_spd_desc (BraseroDeviceHandle *handle,
 	BraseroGetPerformanceCDB *cdb;
 	BraseroScsiResult res;
 
+	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
+
 	cdb = brasero_scsi_command_new (&info, handle);
 	cdb->type = BRASERO_GET_PERFORMANCE_WR_SPEED_TYPE;
 
diff --git a/libbrasero-media/scsi-inquiry.c b/libbrasero-media/scsi-inquiry.c
index de48740..ff5ef3b 100644
--- a/libbrasero-media/scsi-inquiry.c
+++ b/libbrasero-media/scsi-inquiry.c
@@ -93,6 +93,8 @@ brasero_spc1_inquiry (BraseroDeviceHandle *handle,
 	BraseroInquiryCDB *cdb;
 	BraseroScsiResult res;
 
+	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
+
 	cdb = brasero_scsi_command_new (&info, handle);
 	cdb->alloc_len = sizeof (BraseroScsiInquiry);
 
@@ -113,6 +115,8 @@ brasero_spc1_inquiry_is_optical_drive (BraseroDeviceHandle *handle,
 	BraseroScsiInquiry hdr;
 	BraseroScsiResult res;
 
+	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
+
 	cdb = brasero_scsi_command_new (&info, handle);
 	cdb->alloc_len = sizeof (hdr);
 
diff --git a/libbrasero-media/scsi-mech-status.c b/libbrasero-media/scsi-mech-status.c
index 70b9e92..a5d6e39 100644
--- a/libbrasero-media/scsi-mech-status.c
+++ b/libbrasero-media/scsi-mech-status.c
@@ -67,6 +67,8 @@ brasero_mmc1_mech_status (BraseroDeviceHandle *handle,
 	BraseroScsiMechStatusCDB *cdb;
 	BraseroScsiResult res;
 
+	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
+
 	cdb = brasero_scsi_command_new (&info, handle);
 	BRASERO_SET_16 (cdb->len, sizeof (BraseroScsiMechStatusHdr));
 
diff --git a/libbrasero-media/scsi-mode-select.c b/libbrasero-media/scsi-mode-select.c
index 6215597..4fb9f21 100644
--- a/libbrasero-media/scsi-mode-select.c
+++ b/libbrasero-media/scsi-mode-select.c
@@ -98,6 +98,8 @@ brasero_spc1_mode_select (BraseroDeviceHandle *handle,
 	BraseroModeSelectCDB *cdb;
 	BraseroScsiResult res;
 
+	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
+
 	cdb = brasero_scsi_command_new (&info, handle);
 	cdb->PF = 1;
 	cdb->SP = 0;
diff --git a/libbrasero-media/scsi-mode-sense.c b/libbrasero-media/scsi-mode-sense.c
index f03edf3..99635f4 100644
--- a/libbrasero-media/scsi-mode-sense.c
+++ b/libbrasero-media/scsi-mode-sense.c
@@ -112,6 +112,8 @@ brasero_spc1_mode_sense_get_page (BraseroDeviceHandle *handle,
 	BraseroScsiModeData header;
 	BraseroScsiModeData *buffer;
 
+	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
+
 	if (!data || !data_size) {
 		BRASERO_SCSI_SET_ERRCODE (error, BRASERO_SCSI_BAD_ARGUMENT);
 		return BRASERO_SCSI_FAILURE;
diff --git a/libbrasero-media/scsi-prevent-allow-medium-removal.c b/libbrasero-media/scsi-prevent-allow-medium-removal.c
index 90c0021..feed772 100644
--- a/libbrasero-media/scsi-prevent-allow-medium-removal.c
+++ b/libbrasero-media/scsi-prevent-allow-medium-removal.c
@@ -84,6 +84,8 @@ brasero_sbc_medium_removal (BraseroDeviceHandle *handle,
 	BraseroScsiPreventAllowMediumRemovalUnitCDB *cdb;
 	BraseroScsiResult res;
 
+	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
+
 	cdb = brasero_scsi_command_new (&info, handle);
 	cdb->prevent = prevent_removal;
 	res = brasero_scsi_command_issue_sync (cdb,
diff --git a/libbrasero-media/scsi-read-capacity.c b/libbrasero-media/scsi-read-capacity.c
index 461a1fa..33ea09d 100644
--- a/libbrasero-media/scsi-read-capacity.c
+++ b/libbrasero-media/scsi-read-capacity.c
@@ -93,6 +93,8 @@ brasero_mmc2_read_capacity (BraseroDeviceHandle *handle,
 	BraseroReadCapacityCDB *cdb;
 	BraseroScsiResult res;
 
+	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
+
 	/* NOTE: all the fields are ignored by MM drives */
 	cdb = brasero_scsi_command_new (&info, handle);
 
diff --git a/libbrasero-media/scsi-read-cd.c b/libbrasero-media/scsi-read-cd.c
index 0037536..c0a6172 100644
--- a/libbrasero-media/scsi-read-cd.c
+++ b/libbrasero-media/scsi-read-cd.c
@@ -118,6 +118,8 @@ brasero_mmc1_read_block (BraseroDeviceHandle *handle,
 	BraseroReadCDCDB *cdb;
 	BraseroScsiResult res;
 
+	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
+
 	cdb = brasero_scsi_command_new (&info, handle);
 	BRASERO_SET_32 (cdb->start_lba, start);
 
diff --git a/libbrasero-media/scsi-read-disc-info.c b/libbrasero-media/scsi-read-disc-info.c
index 56f042d..baff721 100644
--- a/libbrasero-media/scsi-read-disc-info.c
+++ b/libbrasero-media/scsi-read-disc-info.c
@@ -102,6 +102,8 @@ brasero_mmc1_read_disc_information_std (BraseroDeviceHandle *handle,
 	int request_size;
 	int buffer_size;
 
+	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
+
 	if (!info_return || !size) {
 		BRASERO_SCSI_SET_ERRCODE (error, BRASERO_SCSI_BAD_ARGUMENT);
 		return BRASERO_SCSI_FAILURE;
diff --git a/libbrasero-media/scsi-read-disc-structure.c b/libbrasero-media/scsi-read-disc-structure.c
index ce43f38..8db0d58 100644
--- a/libbrasero-media/scsi-read-disc-structure.c
+++ b/libbrasero-media/scsi-read-disc-structure.c
@@ -158,6 +158,8 @@ brasero_mmc2_read_generic_structure (BraseroDeviceHandle *handle,
 	BraseroReadDiscStructureCDB *cdb;
 	BraseroScsiResult res;
 
+	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
+
 	cdb = brasero_scsi_command_new (&info, handle);
 	cdb->format = type;
 
diff --git a/libbrasero-media/scsi-read-format-capacities.c b/libbrasero-media/scsi-read-format-capacities.c
index 6317649..4eb2727 100644
--- a/libbrasero-media/scsi-read-format-capacities.c
+++ b/libbrasero-media/scsi-read-format-capacities.c
@@ -70,6 +70,8 @@ brasero_mmc2_read_format_capacities (BraseroDeviceHandle *handle,
 	BraseroScsiResult res;
 	int request_size;
 
+	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
+
 	if (!data || !size) {
 		BRASERO_SCSI_SET_ERRCODE (error, BRASERO_SCSI_BAD_ARGUMENT);
 		return BRASERO_SCSI_FAILURE;
diff --git a/libbrasero-media/scsi-read-toc-pma-atip.c b/libbrasero-media/scsi-read-toc-pma-atip.c
index 76adad6..c1eb0e6 100644
--- a/libbrasero-media/scsi-read-toc-pma-atip.c
+++ b/libbrasero-media/scsi-read-toc-pma-atip.c
@@ -175,6 +175,8 @@ brasero_mmc1_read_toc_formatted (BraseroDeviceHandle *handle,
 	BraseroRdTocPmaAtipCDB *cdb;
 	BraseroScsiResult res;
 
+	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
+
 	cdb = brasero_scsi_command_new (&info, handle);
 	cdb->format = BRASERO_RD_TAP_FORMATTED_TOC;
 
@@ -204,6 +206,8 @@ brasero_mmc1_read_toc_raw (BraseroDeviceHandle *handle,
 	BraseroRdTocPmaAtipCDB *cdb;
 	BraseroScsiResult res;
 
+	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
+
 	cdb = brasero_scsi_command_new (&info, handle);
 	cdb->format = BRASERO_RD_TAP_RAW_TOC;
 
@@ -232,6 +236,8 @@ brasero_mmc3_read_cd_text (BraseroDeviceHandle *handle,
 	BraseroRdTocPmaAtipCDB *cdb;
 	BraseroScsiResult res;
 
+	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
+
 	cdb = brasero_scsi_command_new (&info, handle);
 	cdb->format = BRASERO_RD_TAP_CD_TEXT;
 
@@ -257,6 +263,8 @@ brasero_mmc1_read_atip (BraseroDeviceHandle *handle,
 	BraseroRdTocPmaAtipCDB *cdb;
 	BraseroScsiResult res;
 
+	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
+
 	/* In here we have to ask how many bytes the drive wants to return first
 	 * indeed there is a difference in the descriptor size between MMC1/MMC2
 	 * and MMC3. */
diff --git a/libbrasero-media/scsi-read-track-information.c b/libbrasero-media/scsi-read-track-information.c
index 9415565..37644f2 100644
--- a/libbrasero-media/scsi-read-track-information.c
+++ b/libbrasero-media/scsi-read-track-information.c
@@ -175,6 +175,8 @@ brasero_mmc1_read_track_info (BraseroDeviceHandle *handle,
 	BraseroRdTrackInfoCDB *cdb;
 	BraseroScsiResult res;
 
+	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
+
 	cdb = brasero_scsi_command_new (&info, handle);
 	cdb->addr_num_type = BRASERO_FIELD_TRACK_NUM;
 	BRASERO_SET_32 (cdb->blk_addr_trk_ses_num, track_num);
diff --git a/libbrasero-media/scsi-read10.c b/libbrasero-media/scsi-read10.c
index df94d61..bd5d79d 100644
--- a/libbrasero-media/scsi-read10.c
+++ b/libbrasero-media/scsi-read10.c
@@ -101,6 +101,8 @@ brasero_sbc_read10_block (BraseroDeviceHandle *handle,
 	BraseroRead10CDB *cdb;
 	BraseroScsiResult res;
 
+	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
+
 	cdb = brasero_scsi_command_new (&info, handle);
 	BRASERO_SET_32 (cdb->start_address, start);
 
diff --git a/libbrasero-media/scsi-sg.c b/libbrasero-media/scsi-sg.c
index 6769a7e..8e88e1a 100644
--- a/libbrasero-media/scsi-sg.c
+++ b/libbrasero-media/scsi-sg.c
@@ -110,6 +110,8 @@ brasero_scsi_command_issue_sync (gpointer command,
 	BraseroScsiResult res;
 	BraseroScsiCmd *cmd;
 
+	g_return_val_if_fail (command != NULL, BRASERO_SCSI_FAILURE);
+
 	cmd = command;
 	brasero_sg_command_setup (&transport,
 				  sense_buffer,
@@ -140,6 +142,8 @@ brasero_scsi_command_new (const BraseroScsiCmdInfo *info,
 {
 	BraseroScsiCmd *cmd;
 
+	g_return_val_if_fail (handle != NULL, NULL);
+
 	/* make sure we can set the flags of the descriptor */
 
 	/* allocate the command */
diff --git a/libbrasero-media/scsi-test-unit-ready.c b/libbrasero-media/scsi-test-unit-ready.c
index 8060025..65e228f 100644
--- a/libbrasero-media/scsi-test-unit-ready.c
+++ b/libbrasero-media/scsi-test-unit-ready.c
@@ -59,6 +59,8 @@ brasero_spc1_test_unit_ready (BraseroDeviceHandle *handle,
 	BraseroTestUnitReadyCDB *cdb;
 	BraseroScsiResult res;
 
+	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
+
 	cdb = brasero_scsi_command_new (&info, handle);
 	res = brasero_scsi_command_issue_sync (cdb,
 					       NULL,
diff --git a/plugins/checksum/burn-checksum-files.c b/plugins/checksum/burn-checksum-files.c
index d6388e8..cbd6011 100644
--- a/plugins/checksum/burn-checksum-files.c
+++ b/plugins/checksum/burn-checksum-files.c
@@ -421,6 +421,8 @@ brasero_checksum_files_merge_with_former_session (BraseroChecksumFiles *self,
 	burner = brasero_medium_get_drive (medium);
 	device = brasero_drive_get_device (burner);
 	dev_handle = brasero_device_handle_open (device, FALSE, NULL);
+	if (!dev_handle)
+		return BRASERO_BURN_ERR;
 
 	vol = brasero_volume_source_open_device_handle (dev_handle, error);
 	file = brasero_volume_get_file (vol,
@@ -841,6 +843,9 @@ brasero_checksum_files_check_files (BraseroChecksumFiles *self,
 
 	device = brasero_drive_get_device (brasero_medium_get_drive (medium));
 	dev_handle = brasero_device_handle_open (device, FALSE, NULL);
+	if (!dev_handle)
+		return BRASERO_BURN_ERROR;
+
 	vol = brasero_volume_source_open_device_handle (dev_handle, error);
 
 	/* open checksum file */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]