Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2223919pxj; Sun, 30 May 2021 18:31:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQj56mYhT81lsJ9r55dzTbdhzhBNsjG1z6gEcb+I8KH6/3o26ZiHtnggvEi572i4EpiN1F X-Received: by 2002:a17:906:7b88:: with SMTP id s8mr15805515ejo.525.1622424687224; Sun, 30 May 2021 18:31:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622424687; cv=none; d=google.com; s=arc-20160816; b=ZVG6r5QM9mssvIN5m5ernu4zxtu5A14tb4lgIRi1Q0UQGrMQgUsaVp3tIXnTYUn35b eMdxNbJABavhWjstinUhmsrUTzh018ugAplrnZYQsd9xcoTSrkaAbkn8box+l15odJqS ioWWx5Xj5k8IEaEgm4OIxi258X8LJKoFIYllo61xKnVMzyMQD3xBB5dx5/NWTy+oOMZv wh8PbJ7Ptb+6Bri17dRs52qIH2GT/R218yIU9TlPgBWrXcm27Xqlz2xG7oFlv0Dnoy3t wntKDk4PKic3FV5ljUt4YDV87f5Ri+V2wij7PZsDmWTvMPlKhi5z/5Rhq9lKxBs4r+xF sXQw== 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=XO4bir08fTFTlHn2cINIscvF5RvrvZGMbZJU1KkDoYE=; b=C+rKIfsOPLUKwbzlrY7M2KLLGZzvRhVa6XE2RACD0hw09CbeiBKAkicc2qLyGHsjI3 5+RpPx5aozuNIWVypIW/07+v6chUzYt3f77+LkaHzji6/otaAHut8YpBkZrUfcCyUouw deUxVd5RdLCrg1D890fDwxKldSY1KO+q/lot3pLzY1NctQx6/7JYCrey+WpWExQzVbr5 h0buQkA2Px1gYYSWi4wi6mbpFNRfLwfYYgt2kcbk4bJBFtdVs2B/hG4GGhkFVjXk24aG +tqNeeTa70bdLhTyGHQiqRZuNe9dUGUG22N6ApRajE2nmm2bfBgSpS1Epkdrt5dGC5nu xIBg== 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 lz7si4196775ejb.40.2021.05.30.18.31.02; Sun, 30 May 2021 18:31:27 -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 S229897AbhEaBcH (ORCPT + 99 others); Sun, 30 May 2021 21:32:07 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:6079 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229891AbhEaBcG (ORCPT ); Sun, 30 May 2021 21:32:06 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Ftd2Q5N1BzYmkL for ; Mon, 31 May 2021 09:27:42 +0800 (CST) Received: from dggpemm500014.china.huawei.com (7.185.36.153) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 31 May 2021 09:30:25 +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, 31 May 2021 09:30:24 +0800 Subject: [PATCH V2 06/12] append_pathname: check the value returned by realloc to avoid segfault From: Wu Guanghao To: , =?UTF-8?B?0JHQu9Cw0LPQvtC00LDRgNC10L3QutC+INCQ0YDRgtGR0Lw=?= CC: , References: <00ad4a90-8a40-24c1-98d9-eb5f0da42436@huawei.com> Message-ID: <892d9908-2346-f410-3e25-87bd0b458a2e@huawei.com> Date: Mon, 31 May 2021 09:30:24 +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: <00ad4a90-8a40-24c1-98d9-eb5f0da42436@huawei.com> Content-Type: text/plain; charset="gbk" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.184] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) 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"); + chdir(homedir); + abort(); + } + name->path = path; strcpy(&name->path[name->len], str); name->len += len; } --