linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eryu Guan <guaneryu@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Eryu Guan <guaneryu@gmail.com>
Subject: [PATCH] btrfs-progs: fix segfault when listing column OTIME on big endian host
Date: Thu, 25 Jul 2013 17:32:29 +0800	[thread overview]
Message-ID: <1374744749-12231-1-git-send-email-guaneryu@gmail.com> (raw)

The second btrfs command segfaults on big endian host(ppc64)

	btrfs subvolume snapshot /mnt/btrfs /mnt/btrfs/snap
	btrfs subvolume list -s /mnt/btrfs

And ltrace shows

	localtime(0x10029c482d0)                 = 0
	strftime( <no return ...>
	--- SIGSEGV (Segmentation fault) ---

The corresponding code

btrfs-list.c:
        case BTRFS_LIST_OTIME:
                if (subv->otime)
                        strftime(tstr, 256, "%Y-%m-%d %X",
                                 localtime(&subv->otime));
                else
                        strcpy(tstr, "-");
                printf("%s", tstr);
                break;

localtime() returned NULL then strftime() got SIGSEGV.

The reason is that ri->otime.sec is stored as little endian but
assigned to 't' without conversion.

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
---
 btrfs-list.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/btrfs-list.c b/btrfs-list.c
index 4fab858..ca1bae8 100644
--- a/btrfs-list.c
+++ b/btrfs-list.c
@@ -1052,7 +1052,7 @@ static int __list_subvol_search(int fd, struct root_lookup *root_lookup)
 				flags = btrfs_root_flags(ri);
 				if(sh.len >
 				   sizeof(struct btrfs_root_item_v0)) {
-					t = ri->otime.sec;
+					t = le64_to_cpu(ri->otime.sec);
 					ogen = btrfs_root_otransid(ri);
 					memcpy(uuid, ri->uuid, BTRFS_UUID_SIZE);
 					memcpy(puuid, ri->parent_uuid, BTRFS_UUID_SIZE);
-- 
1.8.3.1


             reply	other threads:[~2013-07-25  9:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-25  9:32 Eryu Guan [this message]
2013-07-25 11:21 ` [PATCH] btrfs-progs: fix segfault when listing column OTIME on big endian host Miao Xie
2013-07-25 14:12   ` [PATCH v2] " Eryu Guan
2013-07-25 21:25     ` Zach Brown
2013-07-26  4:34       ` Eryu Guan
2013-08-01 21:08     ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1374744749-12231-1-git-send-email-guaneryu@gmail.com \
    --to=guaneryu@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).