From nobody Tue May 14 19:27:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=fail (Bad Signature) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1681898863641623.9876839888665; Wed, 19 Apr 2023 03:07:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.523292.813198 (Exim 4.92) (envelope-from ) id 1pp4iK-0006Ny-A1; Wed, 19 Apr 2023 10:07:00 +0000 Received: by outflank-mailman (output) from mailman id 523292.813198; Wed, 19 Apr 2023 10:07:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pp4iK-0006Nr-7I; Wed, 19 Apr 2023 10:07:00 +0000 Received: by outflank-mailman (input) for mailman id 523292; Wed, 19 Apr 2023 10:06:58 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pp4iI-0006Nl-Mi for xen-devel@lists.xenproject.org; Wed, 19 Apr 2023 10:06:58 +0000 Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.221]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ea069586-de99-11ed-8611-37d641c3527e; Wed, 19 Apr 2023 12:06:56 +0200 (CEST) Received: from sender by smtp.strato.de (RZmta 49.4.0 AUTH) with ESMTPSA id x6987cz3JA6irpu (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 19 Apr 2023 12:06:44 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ea069586-de99-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; t=1681898804; cv=none; d=strato.com; s=strato-dkim-0002; b=G3w2mbEJJfgCZHDoE6CwY7Ya//D1yAoOULQRypOXY8zxn9mRq1c9EcusXa9uEmdzsZ nlB3O5pjmlZZoEQkden5vIVd9ldDCMBfk1IOwLMYMPJmMxDb6q1Mz7NETgthG+lTzXTW k8a3z6drrS7RqD7wV9WFt2GACTzoaqk9l/T6mBIvZt5bDqJKMMgUc4WEd9MvWLBG9iHq oN22Wyh0rO7AgX+q49kGm5sqVp7q0qRbmBXo3g720HBmvQhbwJHztN71vDrV9/W/YeT5 qmS6S70L3EffHduBXVpYOMFXQp+j/YRYP5E0+CXgk+p8DDGvmuSb0ZxHyQMc68qRFOMy ZdAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1681898804; s=strato-dkim-0002; d=strato.com; h=Message-Id:Date:Subject:Cc:To:From:Cc:Date:From:Subject:Sender; bh=c1TYgW//a9TczZT7Hvd8U4aS6et0hLk47l2yhUc1fsw=; b=JToD897sebkm3zW7d5nmtM2r4dXRgFet4dR2ShIEDId3g7U0T59xtzZ6uJVR5mXKwY vevXLMilymdTM3eQt+h3zBKdQEjGFzflc4vlYCTL5TGtDqNa7bpcXtAhyRo64mEKUFfl RfDlkQQSlTt6XpCfO8lbhXgNwtV4PieBmIi8vUylG1y80JRTIA7z3r+Qgkzdc5EERp4i RXFcCKOWgN+A0SFBrpcoL2HCOJ6iQUuu/6iV+BaWLAoobFI0k0u4Lsr8RRIXcCzEzLCb RZDaIX0Cb2guCZoz6VZJfHC5peimQtOs3pw9IPBrHRNStku3MMtFGSOFfTxa8lSUZrig qSxg== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1681898804; s=strato-dkim-0002; d=aepfle.de; h=Message-Id:Date:Subject:Cc:To:From:Cc:Date:From:Subject:Sender; bh=c1TYgW//a9TczZT7Hvd8U4aS6et0hLk47l2yhUc1fsw=; b=qohYo94XsdlTQzRChdKqvHZe2+8FeW4GMZdhNcY9eGtG4Z1LwG7sN9gJvLIXHAHOHU L6dM7jUXDT2eNr0d6j7zFCqu4k/lihm1IvX+Rq08Pa7rOt+pzxk7gGqnZWx0qzyPPgWR OF3GS4STtOegdxiEiXbuac/2rDRVxTYGxsuTHn6qmAuyWXg9yjng0+0exZ2NzIdZltKm qwc9itmSm6BSBHNJ4ohJDdUPkFuPmYKu8/KQd/OR0wiJ4BAclFYGkigJN88LxlWmBvHc IGLzUC9OgwEyec6Z3O721rfSo1WondAfHVy8dPLtCuegVKGJiaFzdAShZFtP9cRRhQhq p1Uw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1681898804; s=strato-dkim-0003; d=aepfle.de; h=Message-Id:Date:Subject:Cc:To:From:Cc:Date:From:Subject:Sender; bh=c1TYgW//a9TczZT7Hvd8U4aS6et0hLk47l2yhUc1fsw=; b=f8EnrHHbZwtJj7ZAJ88U3OqpTa49P/6rMBVpt3yFVCQJGmWL2I0qVG26HJywNKkRC5 DOznU1EmQ2kjW+FsPkBA== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAg4wqlr7GpgtSxIX+ZWs95M7PYKTHoBaxED20qrwFA==" From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH v1] tools/libs/guest: assist gcc13's realloc analyzer Date: Wed, 19 Apr 2023 10:06:33 +0000 Message-Id: <20230419100633.13047-1-olaf@aepfle.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (found 2 invalid signatures) X-ZM-MESSAGEID: 1681898865718100001 Content-Type: text/plain; charset="utf-8" gcc13 fails to track the allocated memory in backup_ptes: xg_offline_page.c: In function 'backup_ptes': xg_offline_page.c:191:13: error: pointer 'orig' may be used after 'realloc'= [-Werror=3Duse-after-free] 191 | free(orig); Assist the analyzer by slightly rearranging the code: In case realloc succeeds, the previous allocation is either extended or released internally. In case realloc fails, the previous allocation is left unchanged. Return an error in this case, the caller will release the currently allocated memory in its error path. http://bugzilla.suse.com/show_bug.cgi?id=3D1210570 Signed-off-by: Olaf Hering Reviewed-by: Juergen Gross --- tools/libs/guest/xg_offline_page.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tools/libs/guest/xg_offline_page.c b/tools/libs/guest/xg_offli= ne_page.c index ccd0299f0f..8f0a252417 100644 --- a/tools/libs/guest/xg_offline_page.c +++ b/tools/libs/guest/xg_offline_page.c @@ -181,18 +181,14 @@ static int backup_ptes(xen_pfn_t table_mfn, int offse= t, =20 if (backup->max =3D=3D backup->cur) { - void *orig =3D backup->entries; + void *entries =3D realloc(backup->entries, backup->max * 2 * + sizeof(struct pte_backup_entry)); =20 - backup->entries =3D realloc( - orig, backup->max * 2 * sizeof(struct pte_backup_entry)); - - if (backup->entries =3D=3D NULL) - { - free(orig); + if (entries =3D=3D NULL) return -1; - } - else - backup->max *=3D 2; + + backup->entries =3D entries; + backup->max *=3D 2; } =20 backup->entries[backup->cur].table_mfn =3D table_mfn;