Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3333228pxj; Mon, 24 May 2021 04:26:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzf1HWOt97wEKRx7+gJevZFeRcomqUTlgkA3eDyrKIYsPKVXQo7coDD8382YP8OnJ73aR8s X-Received: by 2002:a6b:4f17:: with SMTP id d23mr14405752iob.91.1621855577006; Mon, 24 May 2021 04:26:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621855576; cv=none; d=google.com; s=arc-20160816; b=CqtAN50VfVet7YXUoRuS4orQ6mghtu2aOTE4OlbIOY97/JgBJ8yZBKpN8treVeN2fi wDuuvg7wOSzUQ+QwLzYihWaMQ19CUZhDH4xccdsHmwstbCnImr+sizF7Ocnwvllh3Xq5 tc0N3e/+gVM7LZNAc1tSyRJqtwIWe3U+kotw1BdSnBTb78sAyvcHWA944zFdjn4HoGiA riawV/kp0A4L0nyckjpcoXIG1leZjoD8rBqyFhoGcSkCbSX5KpcQGlGNEW1GKR6g2mJ3 3lkPK/hKCTEXInGAVXFO5sbfTncAuBOPCC9CE2hnOx1bU1VdX71ABW7t60B22+4hlLRk sF9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:references:cc:to:from :subject; bh=BVfXyp44e4hb4YRG/uFhreI5JHj732pFAXE8nQc8/kQ=; b=TW0RUV7OoKsrWiWXAH9cypGDw9hcQi/OpPDu6D9tV06x4aQEiAUFN4dvP4BywoiDIE rQvGMZq0pf/0aYR+E6mPK6oj0NPYe5f2mzebYtAbg6IP7dSmiy76tTBpD+bLAvioIqMQ skZNlpT8hj/JkZQtFge39BKDpskwmGZ5zghLQrb33h+XA0xslqHD4tMx/tys6egFHBnY Ahj81aVY1q+AcJ8rKVYUJZPQzX3xrRfuMdhQTYYIpZdScKlPO1tCahFbrB3ScOJ6YqAh RDR7gNDEXWbv52cu2auvxNa+jKqPIkmMlYmgRHp6FaeRWbkYxZqxdyFMTKmBuITBUK7T B/cg== 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 d25si13001121jam.64.2021.05.24.04.26.04; Mon, 24 May 2021 04:26:16 -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 S232603AbhEXL01 (ORCPT + 99 others); Mon, 24 May 2021 07:26:27 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:5537 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232516AbhEXLZz (ORCPT ); Mon, 24 May 2021 07:25:55 -0400 Received: from dggems701-chm.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FpZXw4v7TzkYj0 for ; Mon, 24 May 2021 19:21:36 +0800 (CST) Received: from dggpemm500014.china.huawei.com (7.185.36.153) by dggems701-chm.china.huawei.com (10.3.19.178) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 24 May 2021 19:24:26 +0800 Received: from [10.174.179.184] (10.174.179.184) 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; Mon, 24 May 2021 19:24:26 +0800 Subject: [PATCH 08/12] misc: fix potential segmentation fault problem in, scandir() From: Wu Guanghao To: CC: , References: <266bc52e-e279-ce84-0e1f-1405b9bc6174@huawei.com> Message-ID: <4edd3647-80fa-e22f-7da0-4ae504d5aa5e@huawei.com> Date: Mon, 24 May 2021 19:24:26 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.2.1 MIME-Version: 1.0 In-Reply-To: <266bc52e-e279-ce84-0e1f-1405b9bc6174@huawei.com> Content-Type: text/plain; charset="gbk" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.184] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) 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 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++; } --