From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1a52667955dso5796625ad.1 for ; Wed, 19 Apr 2023 16:08:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681945696; x=1684537696; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=GYQPQiwIsc00YddYDgTmlPmiEtXARXv9LZX3Mi6ojpY=; b=GItbBklXidcnvs7LDqkeKLXU7z49Hp3VL4XYB9Qmcxm+rpAfqlU0a2nRcCtmrc7hyK neqMXbI6Onw5Z2zwvaMQy4znQoAN49kkE4iXoe4qvDScCjF1+Kw0t1SU4Suh1iWejlPf /CRz/czLkPVuEXj9zbxFC+TnSGYpPMCEOAlknqrE9fdg54KCiqyS3+RCwaZYSWqvfXv0 t9WM5vh39cJxmwToh2RXd88K3pVtbSZK7SAX2UEvRNJgKbtLDi0W9bI37SsSoJoSkmLk 1cnP2CuGbPu0fIniklpYEj+O6xru+cHh/o5yiQ51PAY9/rAYrmBnGNoV62+/vgtJFnVm xBOA== 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-Google-Smtp-Source: AKy350YDK7tTzcQJmtjJyJuU8A4cZOzKJRrgUyKfEjaxM+jScKHCYmfLaJ1Y+aqb8E8YxaiCQFjexA== 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 From: Alan Modra To: binutils@sourceware.org Subject: ubsan: signed integer overflow in display_debug_lines_raw Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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 List-Id: 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; -- Alan Modra Australia Development Lab, IBM