From patchwork Thu Jul 25 14:12:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eryu Guan X-Patchwork-Id: 2833444 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1E7D7C0319 for ; Thu, 25 Jul 2013 14:13:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E718E20299 for ; Thu, 25 Jul 2013 14:13:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2967920127 for ; Thu, 25 Jul 2013 14:13:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755884Ab3GYONt (ORCPT ); Thu, 25 Jul 2013 10:13:49 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:63295 "EHLO mail-pa0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755457Ab3GYONt (ORCPT ); Thu, 25 Jul 2013 10:13:49 -0400 Received: by mail-pa0-f45.google.com with SMTP id bg4so2038701pad.18 for ; Thu, 25 Jul 2013 07:13:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=5URPc8r7nBau3S1yFb5z7QrwxyoDMgvoxfi/lF7e+0U=; b=ADhqmulLsIPidbLRDyQmHqVuY5RQbye+F+2I1L49qGEUlAY0aohB3DJRoVvPq7DsAW y/fqK+3pNHSfMT8yaXmYKXoYB6wYG+bC6fi/anWIgVd4QmlOKXZnt43I2RaFCnTjzch6 uXNdy5CAfDrxI87r72tBPJWbel08wVicZ3O8DZuSzWyHvsZTAFZQ082nuneWo7OoX2XG gNu/9+SHRMoZG91ZlBgbbci06ry7ayhqFgmhWW1V/WiA/AhhaEfeEpF/uPRc/pou+BMk 8GZb1LxXUa6/K+EE5197FU8NkPQETvdcIBpfZ4arY9AOkjKSJiiipHhf1j4oZJYKLubU U8qQ== X-Received: by 10.68.251.234 with SMTP id zn10mr47562585pbc.188.1374761628512; Thu, 25 Jul 2013 07:13:48 -0700 (PDT) Received: from localhost ([111.199.170.18]) by mx.google.com with ESMTPSA id r7sm34575204pao.18.2013.07.25.07.13.45 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 25 Jul 2013 07:13:47 -0700 (PDT) From: Eryu Guan To: linux-btrfs@vger.kernel.org Cc: Eryu Guan Subject: [PATCH v2] btrfs-progs: fix segfault when listing column OTIME on big endian host Date: Thu, 25 Jul 2013 22:12:01 +0800 Message-Id: <1374761521-17603-1-git-send-email-guaneryu@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <51F10A50.9010308@cn.fujitsu.com> References: <51F10A50.9010308@cn.fujitsu.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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( --- 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 --- v1->v2: use btrfs_stack_timespec_sec() instead of raw convert. Thanks Miao Xie for pointing this out. btrfs-list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/btrfs-list.c b/btrfs-list.c index 4fab858..9deddd5 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 = btrfs_stack_timespec_sec(&ri->otime); ogen = btrfs_root_otransid(ri); memcpy(uuid, ri->uuid, BTRFS_UUID_SIZE); memcpy(puuid, ri->parent_uuid, BTRFS_UUID_SIZE);