Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3333329pxj; Mon, 24 May 2021 04:26:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydohBKaRzWDSDy1qdUc0DbfmUTm6fDgxy6InAhXwUHS1ZtoiawfV1ls9o5u6ad9laTAXyn X-Received: by 2002:a05:6402:26d1:: with SMTP id x17mr25041145edd.14.1621855586783; Mon, 24 May 2021 04:26:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621855586; cv=none; d=google.com; s=arc-20160816; b=ZK0W7HoRmoUXAm/KpgR3bbED1mDb1W665igSToShkZjP1/NnaaPO55wjXK3tKJZdu4 LxqrjgZh1RTSXpLGN3bR25f6ZFQ+X2/fFzca2mk7Q1wicLl0R/4EmBksINdWSvZJRxAL My+FnUimbOUFNIr9gJzYKTgpGGQzMYwfJyRkGyUSsECclSjcQwgKbCY3vmYVbaBDHrPZ X0IbbiP7qVx/jNUhcmEuPSJJ6qMJVa42g7q3kCgT6ZEkCbuHGWO7m4ZvmAUBiDuv0YRE Y514gsH/e3Ue8D7HV90tTieiXQ62FiblU1oXcsNpUaM78kL4SSpP6FhAE0HINJp9o8Zu bDAw== 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=gvqvkjHYNojVSULMSmKJHFuBdcAc5DL0Ajtl6jy7r4g=; b=Gz2Fs3fOIWTIhSJtOwLslUqed+s18vZRmxZDXYr04+Uiz3Gy95XT39bpkkJff99+St r8ObwiHVGCKrW5XJMZlkBcmFxKSfMdjyIC9M7+rdZYhT99dfXpPkin1TSiStPqb1eFm9 vg1HL/T42vCiY3JdLYTgKkQFj30SOYQ+rdQQ5q0Q1psfB78RgvbQvKHVD+abB/3mlMP2 ai+OgJ7bzBAkAIYhHXtJL81rduJzk49OaQ8AesFgZOSPieWwJsfLtzF+2ynfRm0yHbnk O0H573K7zBm65aTied4uY31E2ctPksJcabmZe671EuXi7DSRdH5vn2Zsd+oEUXb1NOHI Fb7Q== 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 n25si12711916edv.9.2021.05.24.04.26.03; Mon, 24 May 2021 04:26:26 -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 S232788AbhEXLYs (ORCPT + 99 others); Mon, 24 May 2021 07:24:48 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:3978 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232783AbhEXLYo (ORCPT ); Mon, 24 May 2021 07:24:44 -0400 Received: from dggems706-chm.china.huawei.com (unknown [172.30.72.58]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4FpZX80cG1zmZk7 for ; Mon, 24 May 2021 19:20:56 +0800 (CST) Received: from dggpemm500014.china.huawei.com (7.185.36.153) by dggems706-chm.china.huawei.com (10.3.19.183) 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:23:15 +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:23:15 +0800 Subject: [PATCH 06/12] append_pathname: check the value returned by realloc to avoid segfault From: Wu Guanghao To: CC: , References: <266bc52e-e279-ce84-0e1f-1405b9bc6174@huawei.com> Message-ID: <07fe127f-3814-7d12-dea6-b84d9ab4410e@huawei.com> Date: Mon, 24 May 2021 19:23:15 +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 append_pathname(), we need to add a new path to save the value returned by realloc, otherwise the name->path may be NULL, causing segfault Signed-off-by: Wu Guanghao Signed-off-by: Zhiqiang Liu --- contrib/fsstress.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/contrib/fsstress.c b/contrib/fsstress.c index 2a983482..530bd920 100644 --- a/contrib/fsstress.c +++ b/contrib/fsstress.c @@ -599,7 +599,7 @@ void add_to_flist(int ft, int id, int parent) void append_pathname(pathname_t * name, char *str) { int len; - + char *path; len = strlen(str); #ifdef DEBUG if (len && *str == '/' && name->len == 0) { @@ -609,7 +609,13 @@ void append_pathname(pathname_t * name, char *str) } #endif - name->path = realloc(name->path, name->len + 1 + len); + path = realloc(name->path, name->len + 1 + len); + if (path == NULL) { + fprintf(stderr, "fsstress: append_pathname realloc failed\n"); + chadir(homedir); + abort(); + } + name->path = path; strcpy(&name->path[name->len], str); name->len += len; } --