[PATCH] Btrfs-progs: fix Segmentation fault of btrfs-convert

2014-07-07 Thread Liu Bo
Recently we merge a memory leak fix, which fails xfstests/btrfs/012,
the cause is that it only frees @fs_devices but leaves it on the global
fs_uuid list, which cause a 'Segmentation fault' over running command
btrfs-convert.  This fixes the problem.

Signed-off-by: Liu Bo 
---
 volumes.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/volumes.c b/volumes.c
index a61928c..8b827fa 100644
--- a/volumes.c
+++ b/volumes.c
@@ -184,11 +184,17 @@ again:
seed_devices = fs_devices->seed;
fs_devices->seed = NULL;
if (seed_devices) {
+   struct btrfs_fs_devices *orig;
+
+   orig = fs_devices;
fs_devices = seed_devices;
+   list_del(&orig->list);
+   free(orig);
goto again;
+   } else {
+   list_del(&fs_devices->list);
+   free(fs_devices);
}
-
-   free(fs_devices);
return 0;
 }
 
-- 
1.8.1.4

--
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


Re: [PATCH] btrfs-progs: Fix segmentation fault

2013-07-03 Thread David Sterba
On Sat, Jun 22, 2013 at 02:39:21PM +0900, Kusanagi Kouichi wrote:
> 'btrfs subvolume delete' crashes with segv if it runs in a detached mount.

One does not even need to do the lazy unmount. If the there are 2
processes attempting to delete the same snapshot and one deletes the
snapshot directory entry between lines 216 and 227,

215 res = test_issubvolume(path);
216 if(res<0){
217 fprintf(stderr, "ERROR: error accessing '%s'\n", path);
218 ret = 12;
219 goto out;
220 }
221 if(!res){
222 fprintf(stderr, "ERROR: '%s' is not a subvolume\n", path);
223 ret = 13;
224 goto out;
225 }
226
227 cpath = realpath(path, 0);

the segfault occurs as well.

david
--
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


Re: [PATCH] btrfs-progs: Fix segmentation fault

2013-07-02 Thread David Sterba
On Sat, Jun 22, 2013 at 02:39:21PM +0900, Kusanagi Kouichi wrote:
> @@ -224,12 +224,10 @@ again:
>   goto out;
>   }
>  
> - cpath = realpath(path, 0);
> - dname = strdup(cpath);
> + dname = strdup(path);

We want realpath() here, and when it returns NULL, there was an
error that should be handled like in other cases where realpath is
used.

>   dname = dirname(dname);
> - vname = strdup(cpath);
> + vname = strdup(path);
>   vname = basename(vname);
> - free(cpath);
>  
>   if( !strcmp(vname,".") || !strcmp(vname,"..") ||
>strchr(vname, '/') ){
--
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


[PATCH] btrfs-progs: Fix segmentation fault

2013-06-21 Thread Kusanagi Kouichi
'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 7f6f86100131 sp 
7fff17917318 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  0x7f6f860ffda6 in __GI___strdup (s=0x0) at strdup.c:41
len = 
new = 
#2  0x00405a3d in cmd_subvol_delete (argc=2, argv=) at 
cmds-subvolume.c:228
res = 
fd = 
len = 
e = 
cnt = 1
ret = 0
args = {fd = 0, name = '\000' ...}
dname = 
vname = 
path = 
#3  0x00403b1a in handle_command_group (grp=grp@entry=0x6500c0 
, argc=2, argv=0x7fff179184e8) at btrfs.c:154
cmd = 0x6500f8
#4  0x00405c26 in cmd_subvolume (argc=, argv=) at cmds-subvolume.c:969
No locals.
#5  0x00403d69 in main (argc=3, argv=0x7fff179184e0) at btrfs.c:295
cmd = 0x6515d0
bname = 

Signed-off-by: Kusanagi Kouichi 
---
 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


[PATCH] Btrfs-progs: fix segmentation fault of "btrfs check"

2013-02-26 Thread Tsutomu Itoh
Segmentation fault occurred in the following command.

 # btrfs check /dev/sdc7
 No valid Btrfs found on /dev/sdc7
 Segmentation fault (core dumped)

Fix it.

Signed-off-by: Tsutomu Itoh 
---
 cmds-check.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index d63e945..5d2e9ed 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -3610,12 +3610,12 @@ int cmd_check(int argc, char **argv)
}
 
info = open_ctree_fs_info(argv[optind], bytenr, rw, 1);
-   uuid_unparse(info->super_copy.fsid, uuidbuf);
-   printf("Checking filesystem on %s\nUUID: %s\n", argv[optind], uuidbuf);
-
if (info == NULL)
return 1;
 
+   uuid_unparse(info->super_copy.fsid, uuidbuf);
+   printf("Checking filesystem on %s\nUUID: %s\n", argv[optind], uuidbuf);
+
if (!extent_buffer_uptodate(info->tree_root->node) ||
!extent_buffer_uptodate(info->dev_root->node) ||
!extent_buffer_uptodate(info->extent_root->node) ||

--
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


[PATCH] Btrfs-progs: fix segmentation fault of 'btrfs-debug-tree -e'

2013-02-18 Thread Liu Bo
Due to some historical reasons, we remove 'printing leaf' part, which'd
lead to 'Segmentation fault' of btrfs-debug-tree -e, this patch adds it
back.

Signed-off-by: Liu Bo 
---
 debug-tree.c |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/debug-tree.c b/debug-tree.c
index f6bd5d8..02b0389 100644
--- a/debug-tree.c
+++ b/debug-tree.c
@@ -52,6 +52,11 @@ static void print_extents(struct btrfs_root *root, struct 
extent_buffer *eb)
if (!eb)
return;
 
+   if (btrfs_is_leaf(eb)) {
+   btrfs_print_leaf(root, eb);
+   return;
+   }
+
size = btrfs_level_size(root, btrfs_header_level(eb) - 1);
nr = btrfs_header_nritems(eb);
for (i = 0; i < nr; i++) {
-- 
1.7.7.6

--
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