From d18017e8b7720f2fb967805880da274c659e4d59 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Nov 03 2009 11:17:58 +0000 Subject: - gdu-volume-monitor: don't crash on NULL devices (#529982) --- diff --git a/gvfs-1.4.2-handle-null-gdudevices.patch b/gvfs-1.4.2-handle-null-gdudevices.patch new file mode 100644 index 0000000..59b9de4 --- /dev/null +++ b/gvfs-1.4.2-handle-null-gdudevices.patch @@ -0,0 +1,404 @@ +From 48cf9c174f347f92c3fab7ff50b38effda0eb78a Mon Sep 17 00:00:00 2001 +From: Tomas Bzatek +Date: Fri, 30 Oct 2009 17:06:26 +0000 +Subject: Gently handle NULL GduDevice objects + +This patch adds bunch of tests for NULL GduDevice objects. According to +gdu docs, there's a possibility to have GduPresentable and no associated +GduDevice. It's not common but true for several special cases - +like GduLinuxMdDrive. + +Signed-off-by: David Zeuthen +--- +diff --git a/monitor/gdu/ggduvolume.c b/monitor/gdu/ggduvolume.c +index 865a7b7..28839fd 100644 +--- a/monitor/gdu/ggduvolume.c ++++ b/monitor/gdu/ggduvolume.c +@@ -172,7 +172,7 @@ static gboolean + update_volume (GGduVolume *volume) + { + GduDevice *device; +- GduPool *pool; ++ GduPool *pool = NULL; + time_t now; + gboolean changed; + gboolean old_can_mount; +@@ -217,10 +217,11 @@ update_volume (GGduVolume *volume) + + /* in with the new */ + device = gdu_presentable_get_device (GDU_PRESENTABLE (volume->gdu_volume)); +- pool = gdu_device_get_pool (device); ++ if (device != NULL) ++ pool = gdu_device_get_pool (device); + + keep_cleartext_volume = FALSE; +- if (gdu_device_is_luks (device)) ++ if (device != NULL && gdu_device_is_luks (device)) + { + const gchar *holder_objpath; + +@@ -287,13 +288,17 @@ update_volume (GGduVolume *volume) + volume->name = gdu_presentable_get_name (GDU_PRESENTABLE (volume->cleartext_gdu_volume)); + + g_free (volume->device_file); +- volume->device_file = g_strdup (gdu_device_get_device_file (luks_cleartext_volume_device)); ++ if (luks_cleartext_volume_device != NULL) ++ volume->device_file = g_strdup (gdu_device_get_device_file (luks_cleartext_volume_device)); ++ else ++ volume->device_file = NULL; + + volume->can_mount = TRUE; + + volume->should_automount = FALSE; + +- g_object_unref (luks_cleartext_volume_device); ++ if (luks_cleartext_volume_device != NULL) ++ g_object_unref (luks_cleartext_volume_device); + } + else + { +@@ -321,7 +326,10 @@ update_volume (GGduVolume *volume) + } + + g_free (volume->device_file); +- volume->device_file = g_strdup (gdu_device_get_device_file (device)); ++ if (device != NULL) ++ volume->device_file = g_strdup (gdu_device_get_device_file (device)); ++ else ++ volume->device_file = NULL; + + volume->can_mount = TRUE; + +@@ -341,14 +349,16 @@ update_volume (GGduVolume *volume) + * nopolicy is only FALSE for "physical" devices - e.g. only "physical" devices will + * be set to be automounted. + */ +- if (gdu_device_get_presentation_nopolicy (device)) ++ if (device != NULL && gdu_device_get_presentation_nopolicy (device)) + volume->should_automount = FALSE; + + g_free (activation_uri); + } + +- g_object_unref (pool); +- g_object_unref (device); ++ if (pool != NULL) ++ g_object_unref (pool); ++ if (device != NULL) ++ g_object_unref (device); + + /* ---------------------------------------------------------------------------------------------------- */ + +@@ -1082,6 +1092,20 @@ g_gdu_volume_mount (GVolume *_volume, + } + + device = gdu_presentable_get_device (GDU_PRESENTABLE (volume->gdu_volume)); ++ ++ if (device == NULL) ++ { ++ simple = g_simple_async_result_new_error (G_OBJECT (volume), ++ callback, ++ user_data, ++ G_IO_ERROR, ++ G_IO_ERROR_FAILED, ++ "Underlying device missing"); ++ g_simple_async_result_complete (simple); ++ g_object_unref (simple); ++ goto out; ++ } ++ + pool = gdu_device_get_pool (device); + + /* Makes no sense to mount +@@ -1129,11 +1153,14 @@ g_gdu_volume_mount (GVolume *_volume, + + luks_cleartext_volume_device = gdu_presentable_get_device (GDU_PRESENTABLE (volume->cleartext_gdu_volume)); + +- object_path_of_cleartext_device = gdu_device_get_object_path (luks_cleartext_volume_device); ++ if (luks_cleartext_volume_device != NULL) ++ { ++ object_path_of_cleartext_device = gdu_device_get_object_path (luks_cleartext_volume_device); + +- mount_cleartext_device (data, object_path_of_cleartext_device); ++ mount_cleartext_device (data, object_path_of_cleartext_device); + +- g_object_unref (luks_cleartext_volume_device); ++ g_object_unref (luks_cleartext_volume_device); ++ } + goto out; + } + +@@ -1551,17 +1578,20 @@ g_gdu_volume_get_identifier (GVolume *_volume, + { + device = gdu_presentable_get_device (GDU_PRESENTABLE (volume->gdu_volume)); + +- label = gdu_device_id_get_label (device); +- uuid = gdu_device_id_get_uuid (device); ++ if (device != NULL) ++ { ++ label = gdu_device_id_get_label (device); ++ uuid = gdu_device_id_get_uuid (device); + +- g_object_unref (device); ++ g_object_unref (device); + +- if (strcmp (kind, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE) == 0) +- id = g_strdup (volume->device_file); +- else if (strcmp (kind, G_VOLUME_IDENTIFIER_KIND_LABEL) == 0) +- id = strlen (label) > 0 ? g_strdup (label) : NULL; +- else if (strcmp (kind, G_VOLUME_IDENTIFIER_KIND_UUID) == 0) +- id = strlen (uuid) > 0 ? g_strdup (uuid) : NULL; ++ if (strcmp (kind, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE) == 0) ++ id = g_strdup (volume->device_file); ++ else if (strcmp (kind, G_VOLUME_IDENTIFIER_KIND_LABEL) == 0) ++ id = strlen (label) > 0 ? g_strdup (label) : NULL; ++ else if (strcmp (kind, G_VOLUME_IDENTIFIER_KIND_UUID) == 0) ++ id = strlen (uuid) > 0 ? g_strdup (uuid) : NULL; ++ } + } + + return id; +@@ -1577,19 +1607,24 @@ g_gdu_volume_enumerate_identifiers (GVolume *_volume) + const gchar *uuid; + + p = g_ptr_array_new (); ++ label = NULL; + + if (volume->gdu_volume != NULL) + { + device = gdu_presentable_get_device (GDU_PRESENTABLE (volume->gdu_volume)); +- label = gdu_device_id_get_label (device); +- uuid = gdu_device_id_get_uuid (device); +- g_object_unref (device); +- +- g_ptr_array_add (p, g_strdup (G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE)); +- if (strlen (label) > 0) +- g_ptr_array_add (p, g_strdup (G_VOLUME_IDENTIFIER_KIND_LABEL)); +- if (strlen (uuid) > 0) +- g_ptr_array_add (p, g_strdup (G_VOLUME_IDENTIFIER_KIND_UUID)); ++ ++ if (device != NULL) ++ { ++ label = gdu_device_id_get_label (device); ++ uuid = gdu_device_id_get_uuid (device); ++ g_object_unref (device); ++ ++ g_ptr_array_add (p, g_strdup (G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE)); ++ if (strlen (label) > 0) ++ g_ptr_array_add (p, g_strdup (G_VOLUME_IDENTIFIER_KIND_LABEL)); ++ if (strlen (uuid) > 0) ++ g_ptr_array_add (p, g_strdup (G_VOLUME_IDENTIFIER_KIND_UUID)); ++ } + } + + g_ptr_array_add (p, NULL); +@@ -1638,8 +1673,11 @@ g_gdu_volume_has_device_file (GGduVolume *volume, + { + GduDevice *luks_cleartext_volume_device; + luks_cleartext_volume_device = gdu_presentable_get_device (GDU_PRESENTABLE (volume->cleartext_gdu_volume)); +- _device_file = gdu_device_get_device_file (luks_cleartext_volume_device); +- g_object_unref (luks_cleartext_volume_device); ++ if (luks_cleartext_volume_device != NULL) ++ { ++ _device_file = gdu_device_get_device_file (luks_cleartext_volume_device); ++ g_object_unref (luks_cleartext_volume_device); ++ } + } + + return g_strcmp0 (_device_file, device_file) == 0; +@@ -1682,8 +1720,11 @@ g_gdu_volume_has_uuid (GGduVolume *volume, + { + GduDevice *luks_cleartext_volume_device; + luks_cleartext_volume_device = gdu_presentable_get_device (GDU_PRESENTABLE (volume->cleartext_gdu_volume)); +- _uuid = gdu_device_id_get_uuid (luks_cleartext_volume_device); +- g_object_unref (luks_cleartext_volume_device); ++ if (luks_cleartext_volume_device != NULL) ++ { ++ _uuid = gdu_device_id_get_uuid (luks_cleartext_volume_device); ++ g_object_unref (luks_cleartext_volume_device); ++ } + } + + return g_strcmp0 (_uuid, uuid) == 0; +diff --git a/monitor/gdu/ggduvolumemonitor.c b/monitor/gdu/ggduvolumemonitor.c +index e81dce2..398fed4 100644 +--- a/monitor/gdu/ggduvolumemonitor.c ++++ b/monitor/gdu/ggduvolumemonitor.c +@@ -779,9 +779,10 @@ should_volume_be_ignored (GduPool *pool, GduVolume *volume, GList *fstab_mount_p + const gchar *type; + + ret = TRUE; +- device = NULL; + + device = gdu_presentable_get_device (GDU_PRESENTABLE (volume)); ++ if (device == NULL) ++ goto out; + + if (gdu_device_get_presentation_hide (device)) + goto out; +@@ -827,7 +828,8 @@ should_volume_be_ignored (GduPool *pool, GduVolume *volume, GList *fstab_mount_p + + out: + +- g_object_unref (device); ++ if (device != NULL) ++ g_object_unref (device); + return ret; + } + +@@ -1269,15 +1271,18 @@ update_volumes (GGduVolumeMonitor *monitor, + + d = gdu_presentable_get_device (p); + +- volume = find_volume_for_device_file (monitor, gdu_device_get_device_file (d)); +- if (volume != NULL) ++ if (d != NULL) + { +- /*g_debug ("removing volume %s", gdu_device_get_device_file (d));*/ +- g_gdu_volume_removed (volume); +- monitor->volumes = g_list_remove (monitor->volumes, volume); +- *removed_volumes = g_list_prepend (*removed_volumes, volume); ++ volume = find_volume_for_device_file (monitor, gdu_device_get_device_file (d)); ++ if (volume != NULL) ++ { ++ /*g_debug ("removing volume %s", gdu_device_get_device_file (d));*/ ++ g_gdu_volume_removed (volume); ++ monitor->volumes = g_list_remove (monitor->volumes, volume); ++ *removed_volumes = g_list_prepend (*removed_volumes, volume); ++ } ++ g_object_unref (d); + } +- g_object_unref (d); + } + + for (l = added; l != NULL; l = l->next) +@@ -1285,9 +1290,12 @@ update_volumes (GGduVolumeMonitor *monitor, + GduPresentable *p = GDU_PRESENTABLE (l->data); + GduDevice *d; + ++ volume = NULL; + d = gdu_presentable_get_device (p); + +- volume = find_volume_for_device_file (monitor, gdu_device_get_device_file (d)); ++ if (d != NULL) ++ volume = find_volume_for_device_file (monitor, gdu_device_get_device_file (d)); ++ + if (volume == NULL) + { + GduPresentable *toplevel_presentable; +@@ -1297,12 +1305,16 @@ update_volumes (GGduVolumeMonitor *monitor, + { + GduDevice *toplevel_device; + ++ drive = NULL; + toplevel_device = gdu_presentable_get_device (toplevel_presentable); +- drive = find_drive_by_device_file (monitor, gdu_device_get_device_file (toplevel_device)); +- /*g_debug ("adding volume %s (drive %s)", +- gdu_device_get_device_file (d), +- gdu_device_get_device_file (toplevel_device));*/ +- g_object_unref (toplevel_device); ++ if (toplevel_device != NULL) ++ { ++ drive = find_drive_by_device_file (monitor, gdu_device_get_device_file (toplevel_device)); ++ /*g_debug ("adding volume %s (drive %s)", ++ gdu_device_get_device_file (d), ++ gdu_device_get_device_file (toplevel_device));*/ ++ g_object_unref (toplevel_device); ++ } + g_object_unref (toplevel_presentable); + } + else +@@ -1320,9 +1332,10 @@ update_volumes (GGduVolumeMonitor *monitor, + monitor->volumes = g_list_prepend (monitor->volumes, volume); + *added_volumes = g_list_prepend (*added_volumes, g_object_ref (volume)); + } +- } ++ } + +- g_object_unref (d); ++ if (d != NULL) ++ g_object_unref (d); + } + + g_list_free (added); +@@ -1579,10 +1592,15 @@ update_discs (GGduVolumeMonitor *monitor, + GduPresentable *p = GDU_PRESENTABLE (l->data); + GduDevice *d; + ++ volume = NULL; ++ mount = NULL; + d = gdu_presentable_get_device (p); + +- volume = find_disc_volume_for_device_file (monitor, gdu_device_get_device_file (d)); +- mount = find_disc_mount_for_volume (monitor, volume); ++ if (d != NULL) ++ { ++ volume = find_disc_volume_for_device_file (monitor, gdu_device_get_device_file (d)); ++ mount = find_disc_mount_for_volume (monitor, volume); ++ } + + if (mount != NULL) + { +@@ -1600,7 +1618,8 @@ update_discs (GGduVolumeMonitor *monitor, + *removed_volumes = g_list_prepend (*removed_volumes, volume); + } + +- g_object_unref (d); ++ if (d != NULL) ++ g_object_unref (d); + } + + for (l = added; l != NULL; l = l->next) +@@ -1609,11 +1628,16 @@ update_discs (GGduVolumeMonitor *monitor, + GduDevice *d; + gboolean is_blank; + ++ volume = NULL; ++ is_blank = TRUE; + d = gdu_presentable_get_device (p); + +- is_blank = gdu_device_optical_disc_get_is_blank (d); ++ if (d != NULL) ++ { ++ is_blank = gdu_device_optical_disc_get_is_blank (d); ++ volume = find_disc_volume_for_device_file (monitor, gdu_device_get_device_file (d)); ++ } + +- volume = find_disc_volume_for_device_file (monitor, gdu_device_get_device_file (d)); + if (volume == NULL) + { + GduPresentable *toplevel_presentable; +@@ -1623,12 +1647,16 @@ update_discs (GGduVolumeMonitor *monitor, + { + GduDevice *toplevel_device; + ++ drive = NULL; + toplevel_device = gdu_presentable_get_device (toplevel_presentable); +- drive = find_drive_by_device_file (monitor, gdu_device_get_device_file (toplevel_device)); +- /*g_debug ("adding volume %s (drive %s)", +- gdu_device_get_device_file (d), +- gdu_device_get_device_file (toplevel_device));*/ +- g_object_unref (toplevel_device); ++ if (toplevel_device != NULL) ++ { ++ drive = find_drive_by_device_file (monitor, gdu_device_get_device_file (toplevel_device)); ++ /*g_debug ("adding volume %s (drive %s)", ++ gdu_device_get_device_file (d), ++ gdu_device_get_device_file (toplevel_device));*/ ++ g_object_unref (toplevel_device); ++ } + g_object_unref (toplevel_presentable); + } + else +@@ -1682,7 +1710,8 @@ update_discs (GGduVolumeMonitor *monitor, + } + } + +- g_object_unref (d); ++ if (d != NULL) ++ g_object_unref (d); + } + + g_list_free (added); +-- +cgit v0.8.2 diff --git a/gvfs-1.4.2-remove-dead-code.patch b/gvfs-1.4.2-remove-dead-code.patch new file mode 100644 index 0000000..02105f9 --- /dev/null +++ b/gvfs-1.4.2-remove-dead-code.patch @@ -0,0 +1,66 @@ +From cd2afbd07bbcf4e7caee1dd0ca1c65d74974884d Mon Sep 17 00:00:00 2001 +From: Tomas Bzatek +Date: Fri, 30 Oct 2009 17:03:35 +0000 +Subject: Remove dead code + +Signed-off-by: David Zeuthen +--- +diff --git a/monitor/gdu/ggduvolumemonitor.c b/monitor/gdu/ggduvolumemonitor.c +index 83d8fc2..e81dce2 100644 +--- a/monitor/gdu/ggduvolumemonitor.c ++++ b/monitor/gdu/ggduvolumemonitor.c +@@ -842,7 +842,6 @@ should_drive_be_ignored (GduPool *pool, GduDrive *d, GList *fstab_mount_points) + GList *l; + + ignored = FALSE; +- device = NULL; + enclosed = NULL; + + device = gdu_presentable_get_device (GDU_PRESENTABLE (d)); +@@ -1074,7 +1073,7 @@ find_disc_volume_for_device_file (GGduVolumeMonitor *monitor, + + static GGduVolume * + find_volume_for_device_file (GGduVolumeMonitor *monitor, +- const gchar *device_file) ++ const gchar *device_file) + { + GList *l; + GGduVolume *ret; +@@ -1183,9 +1182,6 @@ update_drives (GGduVolumeMonitor *monitor, + for (l = removed; l != NULL; l = l->next) + { + GduPresentable *p = GDU_PRESENTABLE (l->data); +- GduDevice *d; +- +- d = gdu_presentable_get_device (p); + + drive = find_drive_by_presentable (monitor, p); + if (drive != NULL) +@@ -1195,16 +1191,11 @@ update_drives (GGduVolumeMonitor *monitor, + monitor->drives = g_list_remove (monitor->drives, drive); + *removed_drives = g_list_prepend (*removed_drives, drive); + } +- if (d != NULL) +- g_object_unref (d); + } + + for (l = added; l != NULL; l = l->next) + { + GduPresentable *p = GDU_PRESENTABLE (l->data); +- GduDevice *d; +- +- d = gdu_presentable_get_device (p); + + drive = find_drive_by_presentable (monitor, p); + if (drive == NULL) +@@ -1217,8 +1208,6 @@ update_drives (GGduVolumeMonitor *monitor, + *added_drives = g_list_prepend (*added_drives, g_object_ref (drive)); + } + } +- if (d != NULL) +- g_object_unref (d); + } + + g_list_free (added); +-- +cgit v0.8.2 diff --git a/gvfs.spec b/gvfs.spec index d39d62d..9c66fd0 100644 --- a/gvfs.spec +++ b/gvfs.spec @@ -1,7 +1,7 @@ Summary: Backends for the gio framework in GLib Name: gvfs Version: 1.4.1 -Release: 2%{?dist} +Release: 3%{?dist} License: LGPLv2+ Group: System Environment/Libraries URL: http://www.gtk.org @@ -20,7 +20,7 @@ BuildRequires: gnome-keyring-devel BuildRequires: intltool BuildRequires: gettext-devel BuildRequires: GConf2-devel -BuildRequires: gnome-disk-utility-devel >= 2.28.0 +BuildRequires: gnome-disk-utility-devel >= 2.28.1-1 BuildRequires: PolicyKit-devel # This is a hack until the xfce4-notifyd dependency issue is fixed # https://fedorahosted.org/rel-eng/ticket/1788 @@ -42,6 +42,8 @@ Patch2: http-icons.patch # from upstream Patch12: gvfs-1.4.1-http-suport-stream-query-info.patch Patch13: gvfs-1.4.1-http-soup-header-parsing.patch +Patch14: gvfs-1.4.2-remove-dead-code.patch +Patch15: gvfs-1.4.2-handle-null-gdudevices.patch %description The gvfs package provides backend implementations for the gio @@ -138,6 +140,8 @@ and iPod Touches to applications using gvfs. %patch2 -p1 -b .http-icons %patch12 -p1 -b .http-query-info %patch13 -p1 -b .http-headers +%patch14 -p1 -b .dead-code +%patch15 -p1 -b .gdu-null-devices %build @@ -303,6 +307,9 @@ killall -USR1 gvfsd >&/dev/null || : %{_datadir}/gvfs/remote-volume-monitors/afc.monitor %changelog +* Tue Nov 3 2009 Tomas Bzatek - 1.4.1-3 +- gdu-volume-monitor: don't crash on NULL devices (#529982) + * Mon Nov 2 2009 Tomas Bzatek - 1.4.1-2 - Reload .mount files when single package is installed