Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp126594pxv; Wed, 30 Jun 2021 01:28:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlL/2gmMx/C0kZeyByQaoVmCNQjTEv1jeNJHIKkt95so+2Zyj4oauKSBh84CFpJJwK4Fo7 X-Received: by 2002:a05:6638:2143:: with SMTP id z3mr7949278jaj.103.1625041689538; 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=v2GXFuXkN4tu0zoIIqeJC4asjoMWEQfEgkgwvqpv5eyEhdMUdShaJmk8/GDWe3UjD5 +9aYHr8t6r/a053vtjxJuwmAxoOqvYkCGHBsIdGq+47QLKsV2vJbdxJO5P81jzmMV6UF bPGakz+ldTYxD22Wnx2xuON3uWIjkT9biCA2T7KNMacZaqJmpW8T5BfqDVw/TuDO3MRl Mor9WPlYLnpXKNwOOf2ODqkGPuYW8e+VBwPMW8f8BHX/q5dgZZjqGeD+EN9ym2PStM7Q Zh1kLaEiGmT31BC3BpwhnZXyBrKeal3yQQic/uQMapXbv1yH2kKRSOZlXfMCkD8Pqhtm LIlw== 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=SY+ImXW/QK0RBLAWa/GR0rmwNWm2vPSdMrySRZUN8b8=; b=CVx4jtyaar77JEjq/UbTfj+94k55Vw5RCJFedIXcDpKaQVXWvTus/EiRWy02DLM1s+ ksyn9u0G5YUZmkLjY+jHye4ANORGRaeibWxkLzQaDisxH21uTciMkvBfOShxz0P3KfAb 0Kzo6GogAbewfKLj8wQI3hoHG3gqMZqHnL/gEC8CNDl4CSt0U88yEq1Xd+aQbAHhTfkq vcRWAIpHd2MRZOOp05BotL3SKQykb3QQnWtPlsqSs2VWp6QwNzO3N6TXpHIhBW/6HTs7 iGWDCpBEqlQ2Hj6UYKhAAjQ2gYPuF7F9TfSd3vX57gpBcqcvXJ9+e5Jed9/Hqw+F9chx SJbw== 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 l17si16704239jaj.78.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 S233516AbhF3IaM (ORCPT + 99 others); Wed, 30 Jun 2021 04:30:12 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:6027 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233519AbhF3IaL (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 4GFDq24fynzXmmV 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:34 +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:33 +0800 From: wuguanghao To: , CC: , , Subject: [PATCH v2 08/12] misc: fix potential segmentation fault problem in scandir() Date: Wed, 30 Jun 2021 16:27:20 +0800 Message-ID: <20210630082724.50838-9-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 scandir(), temp_list[num_dent] is allocated by calling malloc(), we should check whether malloc() returns NULL before accessing temp_list[num_dent]. Signed-off-by: Zhiqiang Liu Signed-off-by: Wu Guanghao --- misc/create_inode.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/misc/create_inode.c b/misc/create_inode.c index d62e1cb4..869b0614 100644 --- a/misc/create_inode.c +++ b/misc/create_inode.c @@ -771,6 +771,9 @@ static int scandir(const char *dir_name, struct dirent ***name_list, } // add the copy of dirent to the list temp_list[num_dent] = (struct dirent*)malloc((dent->d_reclen + 3) & ~3); + if (!temp_list[num_dent]) { + goto out; + } memcpy(temp_list[num_dent], dent, dent->d_reclen); num_dent++; } -- 2.19.1