[glib/wip/oholy/gunixmounts-segfaults] gunixmounts: Fix segfaults caused by new filter of mounts



commit e695ca9f310c393d8f39694f77471dbcb06daa9e
Author: Ondrej Holy <oholy redhat com>
Date:   Wed Jan 9 11:04:13 2019 +0100

    gunixmounts: Fix segfaults caused by new filter of mounts
    
    Commit ed88b23f added libmount-based implementation to filter out mounts
    with repeated device path. Unfortunately, this introduced a new bug, which
    may cause segfaults from in certain configurations.
    
    The problem is that `mnt_table_uniq_fs ()` is called from the loop which
    already operates with the `fs` structs from that table. It may happen that
    the current `fs` is removed from the table, which may consequently lead to
    segfaults.
    
    Closes: https://gitlab.gnome.org/GNOME/glib/issues/1645

 gio/gunixmounts.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/gio/gunixmounts.c b/gio/gunixmounts.c
index 8cbd70f5f..6dc774158 100644
--- a/gio/gunixmounts.c
+++ b/gio/gunixmounts.c
@@ -486,6 +486,11 @@ _g_get_unix_mounts (void)
   if (mnt_table_parse_mtab (table, NULL) < 0)
     goto out;
 
+  /* Use only the first mount for device, see comment from _g_get_unix_mounts
+   * in #else branch.
+   */
+  mnt_table_uniq_fs (table, MNT_UNIQ_FORWARD, uniq_fs_source_cmp);
+
   iter = mnt_new_iter (MNT_ITER_FORWARD);
   while (mnt_table_next_fs (table, iter, &fs) == 0)
     {
@@ -494,11 +499,6 @@ _g_get_unix_mounts (void)
       unsigned long mount_flags = 0;
       gboolean is_read_only = FALSE;
 
-      /* Use only the first mount for device, see comment from _g_get_unix_mounts
-       * in #else branch.
-       */
-      mnt_table_uniq_fs (table, MNT_UNIQ_FORWARD, uniq_fs_source_cmp);
-
       device_path = mnt_fs_get_source (fs);
       if (g_strcmp0 (device_path, "/dev/root") == 0)
         device_path = _resolve_dev_root ();


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