Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp126596pxv; Wed, 30 Jun 2021 01:28:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLvK36NZgKfwo0MjHQxC5EioJiSxRrvC06RTxsF44PU3YyiY8uXMfuzFudOSzNX7GZ8tsL X-Received: by 2002:a05:6638:618:: with SMTP id g24mr452771jar.16.1625041689667; Wed, 30 Jun 2021 01:28:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625041689; cv=none; d=google.com; s=arc-20160816; b=rNYYGkCXNamS/GZ4Xx7tKqn+VwLuQEmKGNnmJpPFe6S3f0crSz07iogFTH764y7LVf vlBDJMGjNRc1e5NwwMurgXbuPxQe53NcmJUvnRn5qBw3aQlSNky8umhiKe7NL4+D4hMZ Cd7n3JVvC/noVCyKL/kbMLnq7OnHzTcdHpMGA1wvbRObl85UdOe7giW8v0ezdxFcu2M8 2kok3Vms3zdLU+PzMXSr1lKOM/JycEqJguHi5rfHf0MNmxxRrPO9XYaTJR8j0Phdq3jL FHpcKiCO+eq88xDurRv/GQ3VaJGSFcFeJQ3HpcLeJmQSKGy+Nuhh+Hf4p785a18QTL3V X76A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=SOC3q4Rr7aIx1XWeVdRIKVCgxVpybo9Gq9tINDc5E/s=; b=HBrutHeApNkVdQd76TAPCXIcazyJTJaHgEIuK0kV8zbq8XPfTJMLunh7imEN93kOgM 4EigFgNhOy4zpDBaUYPXpk1OmkabR9vaQB4zxrmu6NVxuSs9RSIPdPKW2HEVBLT3z4+c qSYuPryABXbZyXIpWpxG+eFyFECCIsphnuIG0HbGIOK/fuUxrLwwC2ZWBBzC7zo8CGEz JEcsWW8yTjqrOY+Ltyb3umpRrJxoWo7Nivgm+QwsFJd6AnOmccsUqHYwNwm43vtUCXGO K/SIRIu5F/5EHexr+A8ieRBTWxmSa62Jsy8Wdm6xS0OvOrL6BBtqMfU7ekIEsWT9HybR WlCw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u8si6801998jat.6.2021.06.30.01.27.57; Wed, 30 Jun 2021 01:28:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233514AbhF3IaM (ORCPT + 99 others); Wed, 30 Jun 2021 04:30:12 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:6028 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233516AbhF3IaL (ORCPT ); Wed, 30 Jun 2021 04:30:11 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GFDq252C3zXmpQ for ; Wed, 30 Jun 2021 16:22:22 +0800 (CST) Received: from dggpemm500014.china.huawei.com (7.185.36.153) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 30 Jun 2021 16:27:35 +0800 Received: from huawei.com (10.175.104.170) by dggpemm500014.china.huawei.com (7.185.36.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 30 Jun 2021 16:27:34 +0800 From: wuguanghao To: , CC: , , Subject: [PATCH v2 11/12] misc/lsattr: check whether path is NULL in lsattr_dir_proc() Date: Wed, 30 Jun 2021 16:27:23 +0800 Message-ID: <20210630082724.50838-12-wuguanghao3@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210630082724.50838-2-wuguanghao3@huawei.com> References: <20210630082724.50838-2-wuguanghao3@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.170] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Zhiqiang Liu In lsattr_dir_proc(), if malloc() return NULL, it will cause a segmentation fault problem. Signed-off-by: Zhiqiang Liu Signed-off-by: Wu Guanghao --- misc/lsattr.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/misc/lsattr.c b/misc/lsattr.c index 0d954376..f3212069 100644 --- a/misc/lsattr.c +++ b/misc/lsattr.c @@ -144,6 +144,12 @@ static int lsattr_dir_proc (const char * dir_name, struct dirent * de, int dir_len = strlen(dir_name); path = malloc(dir_len + strlen (de->d_name) + 2); + if (!path) { + fprintf(stderr, "%s", + _("Couldn't allocate path variable " + "in lsattr_dir_proc")); + return -1; + } if (dir_len && dir_name[dir_len-1] == '/') sprintf (path, "%s%s", dir_name, de->d_name); -- 2.19.1