From patchwork Wed Apr 19 23:08:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 85640 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp721050vqo; Wed, 19 Apr 2023 16:08:30 -0700 (PDT) X-Google-Smtp-Source: AKy350aBCavkL/vHHRIrIV1ub1h+ygPNKLFEaAZ6tp2pAobsu8D+FNiNKqeRBxHz6TO7St8yFlR8 X-Received: by 2002:a17:906:8d0b:b0:953:5ff7:7753 with SMTP id rv11-20020a1709068d0b00b009535ff77753mr3307613ejc.11.1681945710174; Wed, 19 Apr 2023 16:08:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681945710; cv=none; d=google.com; s=arc-20160816; b=MUl3/S0z1Syjd9nvrtL9H+fti5p/Jpvjr4Z4Q5oACizPEFbc7jssCnSgrdVsqyP9GA xo55wSTKyLapv7GLH3OXXhp/xoApq/4n5J72AGLbUze+keNxpKAWIikuaENkldQ5bJj7 Efo/WSlVeg0w/gCUym8uByOQ7hUg0F273Mpy+7E5i0CN/PVFY6oaSPIyOaurA8b0Vexx tQPm6arTiAOeUvx8pg2E+Lxvd2Avi+8BDdKhvr8amAZVchWqppa9ZPg7/HIFWYCr3Xhf vi11G9YzSKWZPI6DWRLCqV5aMaWRwMYbXKxEiXartF9xuEz5TW1pnqGka4bASjdMh/3o BuSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=GYQPQiwIsc00YddYDgTmlPmiEtXARXv9LZX3Mi6ojpY=; b=G2UTNBANmNnxL/ar2zX2WRoRQEZbGuLmfXFqvFOyiKJR8Bofl4lFE2D1kJXSt1TnMI KxmHOy43FZFLznEqAgaJpq8B5fh7Dd+04OR8UyElM1fMh+cwEQryFqDkTVZX7kjsIqSE 8irxmyDkxMz5LJxHbqSAlxkKT0DtQtLaeFVlWZPkXIIx1F5WMO7wJhLpddutL52N3NV8 yfGI4Uc03gNBHXxpm0dfE3+I5omi+RAocPgfXVQyOq3E/MMqCSyFWYTQSrefJ45jPN0x WwsF7zkeW1fLRkT6JmOg1AfT0cHcFwbkNugthbndr7oQlx3sdDUEqs7vhqg3F1bwXnH3 7sQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=L5Eplkqj; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id e18-20020a170906505200b0094f6e186c50si67230ejk.295.2023.04.19.16.08.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 16:08:30 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=L5Eplkqj; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 5F8373858C00 for ; Wed, 19 Apr 2023 23:08:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F8373858C00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681945707; bh=GYQPQiwIsc00YddYDgTmlPmiEtXARXv9LZX3Mi6ojpY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=L5Eplkqjs2/nrt6eJVc4QAfrbcZT4EvfVHRdFS5erGYLxRtfjUT5W/0vpMGlXq3rk 1DQM4pESMjxidLfgVoZT9nOVv48dSGLzbL2dgxzzj1IkHI+Jrpk88imPgLCda+NF/p jTZqQdficlU8uKJF0foD8Jokb/EzIDxnpQ34MVlk= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id E45B23858C20 for ; Wed, 19 Apr 2023 23:08:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E45B23858C20 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1a52667955dso5796625ad.1 for ; Wed, 19 Apr 2023 16:08:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681945696; x=1684537696; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GYQPQiwIsc00YddYDgTmlPmiEtXARXv9LZX3Mi6ojpY=; b=iROVXLoYmUEiO9d3GLmSz4GG33UdNsZDHV6stp5bCRauUiqiVIDQ9hq1w1kZvFmKAR +qcWEFKDAzFVvZv7hmU1257pEzv+wzyFnvMDT0kySVONDvteeS2t5/PyFxu9YqvDfS5P xyKv+dI5UHsJA4twmpIS22AoP/VLpNLF7QsBfAxVyX1nzZMcRINOJaaZeXtVKonIjhph /0f4ZfFde+YDFEQ8SkRIOMhRqsbLmJwbYHea7khkHaaNbFB/bdWmPw9Vk4AtxbJkICaf s4ofOVR+gg6W1w3GbDglckvmRLzj/h69sLDCTnP19jE5l95VT6ut08aoIuAzsFZiMzO8 lxnw== X-Gm-Message-State: AAQBX9cBCBYDovOaAeP+KpWo7VxSHsMPDgMRFFWT52JYGAZb/A4cwAio DP313mvPQFaSxhmbu/dMX5tD21mt0mw= X-Received: by 2002:a17:902:e743:b0:1a1:8fd4:251 with SMTP id p3-20020a170902e74300b001a18fd40251mr8397862plf.55.1681945695795; Wed, 19 Apr 2023 16:08:15 -0700 (PDT) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id h16-20020a17090a051000b002409bf5ddfasm32292pjh.35.2023.04.19.16.08.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 16:08:15 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 823F11142CAE; Thu, 20 Apr 2023 08:38:12 +0930 (ACST) Date: Thu, 20 Apr 2023 08:38:12 +0930 To: binutils@sourceware.org Subject: ubsan: signed integer overflow in display_debug_lines_raw Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3035.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alan Modra via Binutils From: Alan Modra Reply-To: Alan Modra Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763647905211609875?= X-GMAIL-MSGID: =?utf-8?q?1763647905211609875?= This one was caused by me unnecessarily promoting an "int adv" to "int64_t adv". The expression overflowing was 4259 + 9223372036854775807 with the left number being unsigned int. * dwarf.h (DWARF2_Internal_LineInfo): Replace unsigned short with uint16_t and unsigned char with uint8_t. Make li_line_base an int8_t. * dwarf.c (display_debug_lines_raw): Revert "adv" back to an int. diff --git a/binutils/dwarf.c b/binutils/dwarf.c index 1001a11db40..8a20bf2a349 100644 --- a/binutils/dwarf.c +++ b/binutils/dwarf.c @@ -4670,7 +4670,7 @@ display_debug_lines_raw (struct dwarf_section * section, while (data < end_of_sequence) { unsigned char op_code; - int64_t adv; + int adv; uint64_t uladv; printf (" [0x%08tx]", data - start); @@ -4717,7 +4717,7 @@ display_debug_lines_raw (struct dwarf_section * section, } adv = (op_code % linfo.li_line_range) + linfo.li_line_base; state_machine_regs.line += adv; - printf (_(" and Line by %" PRId64 " to %d"), + printf (_(" and Line by %d to %d"), adv, state_machine_regs.line); if (verbose_view || state_machine_regs.view) printf (_(" (view %u)\n"), state_machine_regs.view); @@ -4782,7 +4782,7 @@ display_debug_lines_raw (struct dwarf_section * section, case DW_LNS_advance_line: READ_SLEB (adv, data, end); state_machine_regs.line += adv; - printf (_(" Advance Line by %" PRId64 " to %d\n"), + printf (_(" Advance Line by %d to %d\n"), adv, state_machine_regs.line); break; @@ -4802,7 +4802,7 @@ display_debug_lines_raw (struct dwarf_section * section, case DW_LNS_negate_stmt: adv = state_machine_regs.is_stmt; adv = ! adv; - printf (_(" Set is_stmt to %" PRId64 "\n"), adv); + printf (_(" Set is_stmt to %d\n"), adv); state_machine_regs.is_stmt = adv; break; diff --git a/binutils/dwarf.h b/binutils/dwarf.h index 38fb6b7b7df..d2f95235584 100644 --- a/binutils/dwarf.h +++ b/binutils/dwarf.h @@ -23,18 +23,19 @@ /* Structure found in the .debug_line section. */ typedef struct { - uint64_t li_length; - unsigned short li_version; - unsigned char li_address_size; - unsigned char li_segment_size; - uint64_t li_prologue_length; - unsigned char li_min_insn_length; - unsigned char li_max_ops_per_insn; - unsigned char li_default_is_stmt; - int li_line_base; - unsigned char li_line_range; - unsigned char li_opcode_base; - unsigned int li_offset_size; + uint64_t li_length; + uint16_t li_version; + uint8_t li_address_size; + uint8_t li_segment_size; + uint64_t li_prologue_length; + uint8_t li_min_insn_length; + uint8_t li_max_ops_per_insn; + uint8_t li_default_is_stmt; + int8_t li_line_base; + uint8_t li_line_range; + uint8_t li_opcode_base; + /* Not part of the header. 4 for 32-bit dwarf, 8 for 64-bit. */ + unsigned int li_offset_size; } DWARF2_Internal_LineInfo;