'btrfs subvolume delete' crashes with segv if it runs in a detached mount.

Steps to reprduce:
# mkfs.btrfs /dev/vdb

WARNING! - Btrfs v0.20-rc1 IS EXPERIMENTAL
WARNING! - see http://btrfs.wiki.kernel.org before using

fs created label (null) on /dev/vdb
        nodesize 4096 leafsize 4096 sectorsize 4096 size 2.00GB
Btrfs v0.20-rc1
# mount -t btrfs /dev/vdb /mnt
[  333.689984] device fsid b242775b-5e34-4e8b-8f7f-7db585ba1392 devid 1 transid 
4 /dev/vdb
[  333.691756] btrfs: disk space caching is enabled
# cd /mnt
# btrfs subvolume create vol
Create subvolume './vol'
# btrfs subvolume snapshot vol snap
Create a snapshot of 'vol' in './snap'
# umount -l .
# btrfs subvolume delete snap
[  377.897175] btrfs[1875]: segfault at 0 ip 00007f6f86100131 sp 
00007fff17917318 error 4 in libc-2.17.so[7f6f8607c000+1a4000]
Segmentation fault (core dumped)


Backtrace:
#0  __strlen_sse2 () at ../sysdeps/x86_64/multiarch/../strlen.S:31
No locals.
#1  0x00007f6f860ffda6 in __GI___strdup (s=0x0) at strdup.c:41
        len = <optimized out>
        new = <optimized out>
#2  0x0000000000405a3d in cmd_subvol_delete (argc=2, argv=<optimized out>) at 
cmds-subvolume.c:228
        res = <optimized out>
        fd = <optimized out>
        len = <optimized out>
        e = <optimized out>
        cnt = 1
        ret = 0
        args = {fd = 0, name = '\000' <repeats 976 times>...}
        dname = <optimized out>
        vname = <optimized out>
        path = <optimized out>
#3  0x0000000000403b1a in handle_command_group (grp=grp@entry=0x6500c0 
<subvolume_cmd_group>, argc=2, argv=0x7fff179184e8) at btrfs.c:154
        cmd = 0x6500f8
#4  0x0000000000405c26 in cmd_subvolume (argc=<optimized out>, argv=<optimized 
out>) at cmds-subvolume.c:969
No locals.
#5  0x0000000000403d69 in main (argc=3, argv=0x7fff179184e0) at btrfs.c:295
        cmd = 0x6515d0
        bname = <optimized out>

Signed-off-by: Kusanagi Kouichi <sl...@ac.auone-net.jp>
---
 cmds-subvolume.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index ccb4762..f005ba8 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -203,7 +203,7 @@ static int cmd_subvol_delete(int argc, char **argv)
 {
        int     res, fd, len, e, cnt = 1, ret = 0;
        struct btrfs_ioctl_vol_args     args;
-       char    *dname, *vname, *cpath;
+       char    *dname, *vname;
        char    *path;
 
        if (argc < 2)
@@ -224,12 +224,10 @@ again:
                goto out;
        }
 
-       cpath = realpath(path, 0);
-       dname = strdup(cpath);
+       dname = strdup(path);
        dname = dirname(dname);
-       vname = strdup(cpath);
+       vname = strdup(path);
        vname = basename(vname);
-       free(cpath);
 
        if( !strcmp(vname,".") || !strcmp(vname,"..") ||
             strchr(vname, '/') ){
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to