From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by sourceware.org (Postfix) with ESMTPS id 7DF673861C30 for ; Fri, 20 Mar 2020 02:07:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7DF673861C30 Received: by mail-pj1-x1031.google.com with SMTP id nu11so1817669pjb.1 for ; Thu, 19 Mar 2020 19:07:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=yqiQVXwBhT36LM12vKo0adrQWObIYSIKG01ZKss2wCg=; b=Wt5/KCHUeNUjPyMyfjyxsvyHNFfrvxjZOe3YYFz+k7O8xjSDiZxc3AQ3KcnmEuIBAp cqOp/5tuma6mZiaEqfWspCIuz5m+bH8sLQ3PIzVbChNHgqxJHZilFT3zXieutCEpjyWT Wn3cfVxrH4wETQBi6KxOexXwzwWRc1COZS78v8Ok2/VdKRHKqAdt1FrEaeLb71TITWqo 2/XB+K9ce32rbQ17h+i4kQB+xe5eGlqrCR73jRYeUJf8SYjGMON4hq2QxkbfmIwi8k9O AM1n/BOb3SMhNb4Fkpeb0D56pjN29cKOjQajPX4isUHf3GzQeYbxc/ZcqF77UonyTqfU MKYw== X-Gm-Message-State: ANhLgQ2N41rQEBK/6rVWESW2iHPkiC9Ea2qghkREFFvbLge3b9vASWaq VG2ljhKk6uoKJJ5QXOW9ZDu/mVfbPFQ= X-Google-Smtp-Source: ADFU+vs0TjcrZTjsGTpEluYXGwwWHGO0EGGGo7IarrJgf4D0dxZ934AxtAtnSP4UqSBtpqlzU5qyGw== X-Received: by 2002:a17:902:61:: with SMTP id 88mr6431732pla.17.1584670078273; Thu, 19 Mar 2020 19:07:58 -0700 (PDT) Received: from bubble.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id e30sm3591531pga.6.2020.03.19.19.07.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2020 19:07:57 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id DAF4280856; Fri, 20 Mar 2020 12:37:53 +1030 (ACDT) Date: Fri, 20 Mar 2020 12:37:53 +1030 From: Alan Modra To: binutils@sourceware.org Subject: NDS32 disassembly of odd sized sections Message-ID: <20200320020753.GG4583@bubble.grove.modra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-Spam-Status: No, score=-25.2 required=5.0 tests=DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Fri, 20 Mar 2020 02:08:00 -0000 Fixes some uninitialized reads. * nds32-dis.c (print_insn_nds32): Remove unnecessary casts. Initialize parts of buffer not written when handling a possible 2-byte insn at end of section. Don't attempt decoding of such an insn by the 4-byte machinery. diff --git a/opcodes/nds32-dis.c b/opcodes/nds32-dis.c index c5874ffb4a..35e4ba0291 100644 --- a/opcodes/nds32-dis.c +++ b/opcodes/nds32-dis.c @@ -985,7 +985,7 @@ print_insn_nds32 (bfd_vma pc, disassemble_info *info) int is_data = FALSE; bfd_boolean found = FALSE; struct nds32_private_data *private_data; - unsigned int size = 16; + unsigned int size; enum map_type mapping_type = MAP_CODE; if (info->private_data == NULL) @@ -1063,6 +1063,7 @@ print_insn_nds32 (bfd_vma pc, disassemble_info *info) /* Fix corner case: there is no next mapping symbol, let mapping type decides size */ + size = 16; if (last_symbol_index + 1 >= info->symtab_size) { if (mapping_type == MAP_DATA0) @@ -1096,7 +1097,7 @@ print_insn_nds32 (bfd_vma pc, disassemble_info *info) size = (pc & 1) ? 1 : 2; /* Read bytes from BFD. */ - info->read_memory_func (pc, (bfd_byte *) buf_data, size, info); + info->read_memory_func (pc, buf_data, size, info); given = 0; given1 = 0; /* Start assembling data. */ @@ -1153,16 +1154,20 @@ print_insn_nds32 (bfd_vma pc, disassemble_info *info) return size; } - status = info->read_memory_func (pc, (bfd_byte *) buf, 4, info); + size = 4; + status = info->read_memory_func (pc, buf, 4, info); if (status) { /* For the last 16-bit instruction. */ - status = info->read_memory_func (pc, (bfd_byte *) buf, 2, info); + size = 2; + status = info->read_memory_func (pc, buf, 2, info); if (status) { - (*info->memory_error_func)(status, pc, info); + (*info->memory_error_func) (status, pc, info); return -1; } + buf[2] = 0; + buf[3] = 0; } insn = bfd_getb32 (buf); @@ -1174,11 +1179,12 @@ print_insn_nds32 (bfd_vma pc, disassemble_info *info) } /* 32-bit instructions. */ + if (size == 4) + print_insn32 (pc, info, insn, NDS32_PARSE_INSN32); else - { - print_insn32 (pc, info, insn, NDS32_PARSE_INSN32); - return 4; - } + info->fprintf_func (info->stream, + _("insufficient data to decode instruction")); + return 4; } /* Ignore disassembling unnecessary name. */ -- Alan Modra Australia Development Lab, IBM