Message ID | 20230104065611.377771-1-indu.bhagat@oracle.com |
---|---|
State | Accepted |
Headers |
Return-Path: <binutils-bounces+ouuuleilei=gmail.com@sourceware.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp5002845wrt; Tue, 3 Jan 2023 22:57:08 -0800 (PST) X-Google-Smtp-Source: AMrXdXvX8wgJ+L5WMSn61dbI4+C6jzDS07AdmxomSmIaA50zE5J6vQXk4rJDJv5YcWqiv6n9jit3 X-Received: by 2002:a17:906:280d:b0:7c1:2a0f:55b1 with SMTP id r13-20020a170906280d00b007c12a0f55b1mr44223475ejc.14.1672815428808; Tue, 03 Jan 2023 22:57:08 -0800 (PST) Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id xc6-20020a170907074600b0084cbcb38374si10357505ejb.478.2023.01.03.22.57.08 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 22:57:08 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=gKwf2XHv; arc=fail (signature failed); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B2DEE3858C27 for <ouuuleilei@gmail.com>; Wed, 4 Jan 2023 06:57:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B2DEE3858C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1672815427; bh=+uEh8dJ7hQrtxN8CCuyDYhF8Li5zEEl+FPim9wGLHJo=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=gKwf2XHv0rmvLa6v3/GAyFnlMrdmD780mCXWNUwOJZLIvjjb8W93wxOUJl01upT76 0J9P9xqT9nymwC3axJdI1gq47W0y1tnZxI0v3XbmfT+r/KxB6MyVZ5F/aZ+FBP+dkf k7otvwW/1driWgNbPxvGfOTDu1yU+5x3zfEHT4EM= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id C7D473858D1E for <binutils@sourceware.org>; Wed, 4 Jan 2023 06:56:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C7D473858D1E Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 303JnJvT013588 for <binutils@sourceware.org>; Wed, 4 Jan 2023 06:56:56 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3mtc0anuj3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for <binutils@sourceware.org>; Wed, 04 Jan 2023 06:56:56 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 3044wqZ1040266 for <binutils@sourceware.org>; Wed, 4 Jan 2023 06:56:55 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2171.outbound.protection.outlook.com [104.47.55.171]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3mw2wf39ar-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for <binutils@sourceware.org>; Wed, 04 Jan 2023 06:56:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P+xU70hnWz43M9TynZBFA75fpnTao7gefkoOSWsEp2nZ+jLIwvcJXwqVTXnGE3EgNXfI3lwpgMZDeEPBWUrkxRZkWTYnNaz7RdcKRuK6Q5lRPW4b4b7KZFCorKQql/BzCehmgJCi/eiLdlO4Vh3SROk6hUpZTNAKHpmFupiHehUf8RmicE71ibNnD9brRb3AVn/lXUrcmSc+JFYQS8x8ar715P+gFNQka0dh7UHeaaE8SpifY9GBJ1isA0NeDGR8vJVQgFMzfXQ7M1/+JbZueJqA37TgalU16+k8pdgtOmAFRbEJsPphAa68IVlx4vQXaXr5avyGbrFV1eIlFEsMHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+uEh8dJ7hQrtxN8CCuyDYhF8Li5zEEl+FPim9wGLHJo=; b=cmxg51T6y8KIiSEz1r3luGbzQSRh8TIikC2e7da8rKMYNPyvHVrMecSi4MokehmdwfXwvhCKWT5yudJEntQyvePRsH5w8y7Eld7oYq/WOqY9AT0Uae2Zn/cWLmCei7Xb2huCBHK1OCJr+2ZxTmzwyj/nVszuS6/IRwU3w7yyzAMMiApUk0DMOmNq9gIZudwq06BHjd86cqjhZBdRdjr8YVpr1qC1M9+YllcHhgPh8kJCYuWFqE7O/kEEqV7mtAkhxQ/kahNvtqvK/qFSsIgQsrRVHa79X11jPbV9URND2zXzhsZRQz/Mqs6rEjIfeV3TSQd7GnlLeeUYZsGXDCu9oA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none Received: from MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) by BN0PR10MB5302.namprd10.prod.outlook.com (2603:10b6:408:117::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.19; Wed, 4 Jan 2023 06:56:53 +0000 Received: from MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::ee70:1952:4416:1bdc]) by MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::ee70:1952:4416:1bdc%5]) with mapi id 15.20.5944.019; Wed, 4 Jan 2023 06:56:53 +0000 To: binutils@sourceware.org Cc: Indu Bhagat <indu.bhagat@oracle.com> Subject: [PATCH] libsframe: adjust an incorrect check in flip_sframe Date: Tue, 3 Jan 2023 22:56:11 -0800 Message-Id: <20230104065611.377771-1-indu.bhagat@oracle.com> X-Mailer: git-send-email 2.37.2 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MW4PR03CA0342.namprd03.prod.outlook.com (2603:10b6:303:dc::17) To MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR1001MB2158:EE_|BN0PR10MB5302:EE_ X-MS-Office365-Filtering-Correlation-Id: 6781d382-549b-4015-bc7a-08daee20dc5f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zgZrecBF9wHuPtXgK3EU1MV5EmV3HIoSAOUxogDGJUx5b+NWhJKxdLeYTSnJcaci1cNuTjitjJZ2qJwmTxf9f8//UqFBdGRBVcQstdvwRMd6NNazlmROuvav1tqSMQc9ufVDAdZ5Cto7UUIWc2kTi5/o1TqQOQpm8cLq1SzqLvHMzeVQYy/fkqOkSRANKc2b3wajkZ86svv5DHyilDj0uiEnVGceeK4rLLPKNJos03xvDOVhWKL039aMQdRpeVg17AJSKQlyYU2IwUeyxDo0bsGQqlBJ/DndnOM1vkWGRb1AwH4pKGj3S5TrT45AcfRCXjUnW5xFnTPG3iuTeJeky4+AJIRack4/1oUm+ZEFZW7k4WmEtMS8m1X+IpWeCkmO5D5zNfip3+iDn5ibh8Iv6n8BlpYVnK8yvxC1Ku+vPwxI5G3XDhMnUcivey11lOjfmB1saavIaoMwiVTvOqWRT1/3yPRLjGDz5RW3P5E7HUEfp9j/ZF1jG17ajVQyTnYbMtz9eLl8kS/4yyQNcG1dhW2OvPUfKDP2jwab6Hv9HfTJqYU20ktFT7C8PmnD0rr/IA+ikJLuTptGigvRctBvsM2u9D/9kW6ntzjNRHCp1Z1mNkSaYsypt3lgrsAnJBysFcmE7TXRci+6ktSB3SNURA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MWHPR1001MB2158.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(396003)(136003)(346002)(376002)(39860400002)(366004)(451199015)(316002)(4326008)(6512007)(6506007)(2906002)(5660300002)(186003)(6916009)(44832011)(6666004)(6486002)(478600001)(41300700001)(107886003)(26005)(86362001)(83380400001)(2616005)(1076003)(38100700002)(66556008)(8676002)(8936002)(66946007)(36756003)(66476007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6QXSGLOGi5WOtlQtZ+TNS9TFK2u4eJ5eE7RAl5xgNCNvJ2hwk2QLnMUDkR4Y5L/BNMDslL6beTUwsLXAxIUYWUza1BH7+YKj2papW/AcHJkUpbsgyTCqYViyT1hB4RLEGsEbodQZxRUXVKI677vDMTVvSE178vS7q6tYk5A0rUze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h/a+O3VnrbFsDHvsfnfY52O9iePptzcF766gZS3FiihI7QnDQZgd2Q9mdbVoDM7AZb8lzduS1Jn/t7BtARIHatCYTdZ0DGyKIlJh6p9 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6781d382-549b-4015-bc7a-08daee20dc5f X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2158.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jan 2023 06:56:53.2472 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: d0asT/85y4MKLFi3f5PktYpPIUW9exMjujPyTl3YkMELRp4hGJJyEX8t5aarIzVM2BQaegmBYZDOOjiWnxGkGQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB5302 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-04_03,2023-01-03_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 phishscore=0 malwarescore=0 suspectscore=0 mlxscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301040057 X-Proofpoint-GUID: jU4DPYM1NVBRDTVfoAbiRbe2rw4s5Ilg X-Proofpoint-ORIG-GUID: jU4DPYM1NVBRDTVfoAbiRbe2rw4s5Ilg X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list <binutils.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/binutils>, <mailto:binutils-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/binutils/> List-Post: <mailto:binutils@sourceware.org> List-Help: <mailto:binutils-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/binutils>, <mailto:binutils-request@sourceware.org?subject=subscribe> From: Indu Bhagat via Binutils <binutils@sourceware.org> Reply-To: Indu Bhagat <indu.bhagat@oracle.com> Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" <binutils-bounces+ouuuleilei=gmail.com@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754074110968256552?= X-GMAIL-MSGID: =?utf-8?q?1754074110968256552?= |
Series |
libsframe: adjust an incorrect check in flip_sframe
|
|
Checks
Context | Check | Description |
---|---|---|
snail/binutils-gdb-check | success | Github commit url |
Commit Message
Indu Bhagat
Jan. 4, 2023, 6:56 a.m. UTC
Hello, While testing the endian flipping code in libsframe, I tried a cross build with --target=x86_64-linux on a big-endian system (ppc64), and I ran into some SFrame testsuite failures: FAIL: SFrame Simple link FAIL: SFrame for plt0 and pltN The reason for failure is explained below in the commit log. This patch fixes the issue. Testing notes: - Reg tested native and cross builds on x86_64 and aarch64 (checked binutils, ld, gas, libctf, libsframe). - try bot shows no new regressions. - Tested ld, gas with a cross build: --target=x86_64-linux on ppc64 host. The two testcase failures are resolved with this patch. Before the patch: FAIL: SFrame Simple link FAIL: SFrame for plt0 and pltN === ld Summary === # of expected passes 1651 # of unexpected failures 2 # of expected failures 3 # of untested testcases 26 # of unsupported tests 134 After the patch: === ld Summary === # of expected passes 1653 # of expected failures 3 # of untested testcases 26 # of unsupported tests 134 OK for master and binutils-2_40-branch ? Thanks -------------------------------------- When sframe_encoder_write needs to flip the buffer containing the SFrame section before writing, it is not necessary that the SFrame FDES are in the order of their sfde_func_start_fre_off. On the contrary, SFrame FDEs will be sorted in the order of their start address. So, remove this incorrect assumption which is basically assuming that the last sfde_func_start_fre_off seen will help determine the end of the flipped buffer. The function now keeps track of the bytes_flipped and then compares it with the expected value. Also, added two more checks at appropriate places: - check that the SFrame FDE read is within bounds - check that the SFrame FRE read is within bounds ChangeLog: * libsframe/sframe.c (flip_sframe): Adjust an incorrect check. Add other checks to ensure reads are within the buffer size. --- libsframe/sframe.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
Comments
On 1/3/23 10:56 PM, Indu Bhagat via Binutils wrote: > Hello, > > While testing the endian flipping code in libsframe, I tried a cross build with > --target=x86_64-linux on a big-endian system (ppc64), and I ran into some > SFrame testsuite failures: > > FAIL: SFrame Simple link > FAIL: SFrame for plt0 and pltN > > The reason for failure is explained below in the commit log. This patch fixes > the issue. > > Testing notes: > - Reg tested native and cross builds on x86_64 and aarch64 (checked binutils, > ld, gas, libctf, libsframe). > - try bot shows no new regressions. > - Tested ld, gas with a cross build: --target=x86_64-linux on ppc64 host. The > two testcase failures are resolved with this patch. > > Before the patch: > FAIL: SFrame Simple link > FAIL: SFrame for plt0 and pltN > > === ld Summary === > > # of expected passes 1651 > # of unexpected failures 2 > # of expected failures 3 > # of untested testcases 26 > # of unsupported tests 134 > > After the patch: > > === ld Summary === > > # of expected passes 1653 > # of expected failures 3 > # of untested testcases 26 > # of unsupported tests 134 > > OK for master and binutils-2_40-branch ? > I have pushed this to master. Is this OK for binutils-2_40-branch ? Without this patch, there will be undesirable effects (failing ld SFrame tests, also meaning limited SFrame functionality) in some cross-builds. Thanks Indu > Thanks > > -------------------------------------- > > When sframe_encoder_write needs to flip the buffer containing the SFrame > section before writing, it is not necessary that the SFrame FDES are in > the order of their sfde_func_start_fre_off. On the contrary, SFrame > FDEs will be sorted in the order of their start address. So, remove > this incorrect assumption which is basically assuming that the last > sfde_func_start_fre_off seen will help determine the end of the flipped > buffer. > > The function now keeps track of the bytes_flipped and then compares it with > the expected value. Also, added two more checks at appropriate places: > - check that the SFrame FDE read is within bounds > - check that the SFrame FRE read is within bounds > > ChangeLog: > > * libsframe/sframe.c (flip_sframe): Adjust an incorrect check. > Add other checks to ensure reads are within the buffer size. > --- > libsframe/sframe.c | 22 +++++++++++++--------- > 1 file changed, 13 insertions(+), 9 deletions(-) > > diff --git a/libsframe/sframe.c b/libsframe/sframe.c > index 4aada1a25e0..d206780289a 100644 > --- a/libsframe/sframe.c > +++ b/libsframe/sframe.c > @@ -401,7 +401,10 @@ flip_sframe (char *frame_buf, size_t buf_size, uint32_t to_foreign) > unsigned int fre_type = 0; > uint32_t fre_offset = 0; > size_t esz = 0; > + size_t hdrsz = 0; > int err = 0; > + /* For error checking. */ > + size_t bytes_flipped = 0; > > /* Header must be in host endianness at this time. */ > ihp = (sframe_header *)frame_buf; > @@ -411,14 +414,18 @@ flip_sframe (char *frame_buf, size_t buf_size, uint32_t to_foreign) > > /* The contents of the SFrame header are safe to read. Get the number of > FDEs and the first FDE in the buffer. */ > + hdrsz = sframe_get_hdr_size (ihp); > num_fdes = ihp->sfh_num_fdes; > - fdes = frame_buf + sframe_get_hdr_size (ihp) + ihp->sfh_fdeoff; > + fdes = frame_buf + hdrsz + ihp->sfh_fdeoff; > fdep = (sframe_func_desc_entry *)fdes; > > j = 0; > prev_frep_index = 0; > for (i = 0; i < num_fdes; fdep++, i++) > { > + if ((char*)fdep >= (frame_buf + buf_size)) > + goto bad; > + > if (to_foreign) > { > num_fres = fdep->sfde_func_num_fres; > @@ -427,6 +434,7 @@ flip_sframe (char *frame_buf, size_t buf_size, uint32_t to_foreign) > } > > flip_fde (fdep); > + bytes_flipped += sizeof (sframe_func_desc_entry); > > if (!to_foreign) > { > @@ -441,20 +449,16 @@ flip_sframe (char *frame_buf, size_t buf_size, uint32_t to_foreign) > { > if (flip_fre (fp, fre_type, &esz)) > goto bad; > + bytes_flipped += esz; > > - if (esz == 0) > + if (esz == 0 || esz > buf_size) > goto bad; > fp += esz; > } > prev_frep_index = j; > } > - /* All FREs must have been endian flipped by now. */ > - if (j != ihp->sfh_num_fres) > - goto bad; > - /* Contents, if any, must have been processed by now. > - Recall that .sframe section with just a SFrame header may be generated by > - GAS if no SFrame FDEs were found for the input file. */ > - if (ihp->sfh_num_fres && ((frame_buf + buf_size) != (void*)fp)) > + /* All FDEs and FREs must have been endian flipped by now. */ > + if ((j != ihp->sfh_num_fres) || (bytes_flipped != (buf_size - hdrsz))) > goto bad; > > /* Success. */ >
Hi Indu, > Is this OK for binutils-2_40-branch ? Without this patch, there will be undesirable effects (failing ld SFrame tests, also meaning limited SFrame functionality) in some > cross-builds. Yes - please apply to the branch. Cheers Nick
diff --git a/libsframe/sframe.c b/libsframe/sframe.c index 4aada1a25e0..d206780289a 100644 --- a/libsframe/sframe.c +++ b/libsframe/sframe.c @@ -401,7 +401,10 @@ flip_sframe (char *frame_buf, size_t buf_size, uint32_t to_foreign) unsigned int fre_type = 0; uint32_t fre_offset = 0; size_t esz = 0; + size_t hdrsz = 0; int err = 0; + /* For error checking. */ + size_t bytes_flipped = 0; /* Header must be in host endianness at this time. */ ihp = (sframe_header *)frame_buf; @@ -411,14 +414,18 @@ flip_sframe (char *frame_buf, size_t buf_size, uint32_t to_foreign) /* The contents of the SFrame header are safe to read. Get the number of FDEs and the first FDE in the buffer. */ + hdrsz = sframe_get_hdr_size (ihp); num_fdes = ihp->sfh_num_fdes; - fdes = frame_buf + sframe_get_hdr_size (ihp) + ihp->sfh_fdeoff; + fdes = frame_buf + hdrsz + ihp->sfh_fdeoff; fdep = (sframe_func_desc_entry *)fdes; j = 0; prev_frep_index = 0; for (i = 0; i < num_fdes; fdep++, i++) { + if ((char*)fdep >= (frame_buf + buf_size)) + goto bad; + if (to_foreign) { num_fres = fdep->sfde_func_num_fres; @@ -427,6 +434,7 @@ flip_sframe (char *frame_buf, size_t buf_size, uint32_t to_foreign) } flip_fde (fdep); + bytes_flipped += sizeof (sframe_func_desc_entry); if (!to_foreign) { @@ -441,20 +449,16 @@ flip_sframe (char *frame_buf, size_t buf_size, uint32_t to_foreign) { if (flip_fre (fp, fre_type, &esz)) goto bad; + bytes_flipped += esz; - if (esz == 0) + if (esz == 0 || esz > buf_size) goto bad; fp += esz; } prev_frep_index = j; } - /* All FREs must have been endian flipped by now. */ - if (j != ihp->sfh_num_fres) - goto bad; - /* Contents, if any, must have been processed by now. - Recall that .sframe section with just a SFrame header may be generated by - GAS if no SFrame FDEs were found for the input file. */ - if (ihp->sfh_num_fres && ((frame_buf + buf_size) != (void*)fp)) + /* All FDEs and FREs must have been endian flipped by now. */ + if ((j != ihp->sfh_num_fres) || (bytes_flipped != (buf_size - hdrsz))) goto bad; /* Success. */