From patchwork Fri Apr 25 10:44:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Bo X-Patchwork-Id: 4059021 X-Patchwork-Delegate: dave@jikos.cz Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8989E9F3EE for ; Fri, 25 Apr 2014 10:44:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C297F203AB for ; Fri, 25 Apr 2014 10:44:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B38E320320 for ; Fri, 25 Apr 2014 10:44:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752845AbaDYKoR (ORCPT ); Fri, 25 Apr 2014 06:44:17 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:25810 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752230AbaDYKoP (ORCPT ); Fri, 25 Apr 2014 06:44:15 -0400 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s3PAiD2V001202 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 25 Apr 2014 10:44:14 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by ucsinet22.oracle.com (8.14.5+Sun/8.14.5) with ESMTP id s3PAiClq028468 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 25 Apr 2014 10:44:13 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s3PAiCeq008333; Fri, 25 Apr 2014 10:44:12 GMT Received: from localhost.localdomain.localdomain (/222.90.43.132) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 25 Apr 2014 03:44:12 -0700 From: Liu Bo To: linux-btrfs@vger.kernel.org Cc: Filipe David Manana Subject: [PATCH v2] Btrfs-progs: set string end sing '\0' for property Date: Fri, 25 Apr 2014 18:44:03 +0800 Message-Id: <1398422643-6741-1-git-send-email-bo.li.liu@oracle.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1398407399-10963-1-git-send-email-bo.li.liu@oracle.com> References: <1398407399-10963-1-git-send-email-bo.li.liu@oracle.com> X-Source-IP: ucsinet22.oracle.com [156.151.31.94] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Set string "xattr_name" 's end with '\0' so that it won't be violated in memory. With this fix, xfstest/btrfs/048 can pass on my box. Signed-off-by: Liu Bo Reviewed-by: Filipe Manana --- v2: avoid buffer overflow of malloc(). props.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/props.c b/props.c index 9ff63ca..cc87454 100644 --- a/props.c +++ b/props.c @@ -131,13 +131,14 @@ static int prop_compression(enum prop_object_type type, goto out; } - xattr_name = malloc(XATTR_BTRFS_PREFIX_LEN + strlen(name)); + xattr_name = malloc(XATTR_BTRFS_PREFIX_LEN + strlen(name) + 1); if (!xattr_name) { ret = -ENOMEM; goto out; } memcpy(xattr_name, XATTR_BTRFS_PREFIX, XATTR_BTRFS_PREFIX_LEN); memcpy(xattr_name + XATTR_BTRFS_PREFIX_LEN, name, strlen(name)); + xattr_name[XATTR_BTRFS_PREFIX_LEN + strlen(name)] = '\0'; if (value) sret = fsetxattr(fd, xattr_name, value, strlen(value), 0);