public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Binutils <binutils@sourceware.org>
Cc: "H.J. Lu" <hjl.tools@gmail.com>
Subject: [PATCH 1/3] x86: work around compiler diagnosing dangling pointer
Date: Mon, 24 Apr 2023 09:34:27 +0200	[thread overview]
Message-ID: <a475270f-97f0-4fc7-bd0c-eb99bd8b2b3c@suse.com> (raw)
In-Reply-To: <61597ebf-cc5e-2029-6520-31f7adfeea68@suse.com>

For quite come time print_insn() has been storing the address of a local
variable into info->private_data. Since the compiler can't know that the
field won't be accessed again after print_insn() returns, it may kind of
legitimately diagnose this. And recent enough gcc does as of the
introduction of the fetch_error() return paths (replacing setjmp()-based
error handling).

Utilizing that neither prefix_name() nor i386_dis_printf() actually use
info->private_data, zap the pointer in fetch_error(), after having
retrieved it for local use.
---
Let's hope that this addresses the observed issues, which I haven't been
seeing myself. And of course there are further return paths which may
(sooner or later) also have such a warning trigger.

--- a/opcodes/i386-dis.c
+++ b/opcodes/i386-dis.c
@@ -345,6 +345,12 @@ fetch_error (const instr_info *ins)
   const struct dis_private *priv = ins->info->private_data;
   const char *name = NULL;
 
+  /* Our caller has put a pointer to a local variable in info->private_data
+     and it is going to return right after this function has returned.  Some
+     compilers diagnose this as a dangling pointer.  Zap the pointer here to
+     avoid needing to do so on all involved return paths in the caller.  */
+  ins->info->private_data = NULL;
+
   if (ins->codep <= priv->the_buffer)
     return -1;
 


  reply	other threads:[~2023-04-24  7:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-24  7:33 [PATCH 0/3] x86: further disassembler tweaks Jan Beulich
2023-04-24  7:34 ` Jan Beulich [this message]
2023-04-24 10:24   ` [PATCH 1/3] x86: work around compiler diagnosing dangling pointer Alan Modra
2023-04-24 10:35     ` Jan Beulich
2023-04-24  7:35 ` [PATCH 2/3] x86: limit data passed to prefix_name() Jan Beulich
2023-04-24  7:35 ` [PATCH 3/3] x86: limit data passed to i386_dis_printf() Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a475270f-97f0-4fc7-bd0c-eb99bd8b2b3c@suse.com \
    --to=jbeulich@suse.com \
    --cc=binutils@sourceware.org \
    --cc=hjl.tools@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).