From 973d9cf9c6092d94a3e5b54e5b8e7cd4e2d705d7 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 25 Oct 2010 12:26:28 +0200 Subject: [PATCH] umount: umount -r segfault umount(8) segfaults when update incomplete mtab file after remount to read-only (-r). For example autofs does not store info about mountpoint to /etc/mtab file. # mount /dev/sda1 /mnt/test # sed -i -e 's:/dev/sda1 .*::g' /etc/mtab # cd /mnt/test # umount -r /mnt/test umount: /mnt/test busy - remounted read-only Segmentation fault The command "umount -r" should not care about /etc/mtab if the related mtab entry does not exist. Reported-by: Paul Crawford Addresses: https://bugs.launchpad.net/bugs/579858 Signed-off-by: Karel Zak --- mount/umount.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mount/umount.c b/mount/umount.c index 49741a51..b5ff8a17 100644 --- a/mount/umount.c +++ b/mount/umount.c @@ -267,15 +267,20 @@ umount_one (const char *spec, const char *node, const char *type, res = mount(spec, node, NULL, MS_MGC_VAL | MS_REMOUNT | MS_RDONLY, NULL); if (res == 0) { - struct my_mntent remnt; fprintf(stderr, _("umount: %s busy - remounted read-only\n"), spec); - remnt.mnt_type = remnt.mnt_fsname = NULL; - remnt.mnt_dir = xstrdup(node); - remnt.mnt_opts = xstrdup("ro"); - if (!nomtab) + if (mc && !nomtab) { + /* update mtab if the entry is there */ + struct my_mntent remnt; + remnt.mnt_fsname = mc->m.mnt_fsname; + remnt.mnt_dir = mc->m.mnt_dir; + remnt.mnt_type = mc->m.mnt_type; + remnt.mnt_opts = "ro"; + remnt.mnt_freq = 0; + remnt.mnt_passno = 0; update_mtab(node, &remnt); + } return 0; } else if (errno != EBUSY) { /* hmm ... */ perror("remount"); -- 2.39.5