linux-debuggers.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Brennan <stephen.s.brennan@oracle.com>
To: Petr Tesarik <petr@tesarici.cz>
Cc: linux-debuggers@vger.kernel.org,
	Stephen Brennan <stephen.s.brennan@oracle.com>
Subject: [PATCH kdumpid 3/3] Gracefully handle missing dissasembler function
Date: Wed, 28 Jun 2023 14:03:44 -0700	[thread overview]
Message-ID: <20230628210344.357073-4-stephen.s.brennan@oracle.com> (raw)
In-Reply-To: <20230628210344.357073-1-stephen.s.brennan@oracle.com>

If disassembler() returns NULL then kdumpid is guaranteed to segfault.
Gracefully return a 0 so we can continue on.

Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
---
 ppc.c   | 2 ++
 ppc64.c | 2 ++
 s390.c  | 2 ++
 x86.c   | 2 ++
 4 files changed, 8 insertions(+)

diff --git a/ppc.c b/ppc.c
index 8d460ae..3683381 100644
--- a/ppc.c
+++ b/ppc.c
@@ -155,5 +155,7 @@ looks_like_kcode_ppc(struct dump_desc *dd, uint64_t addr)
 	print_insn = disassembler(bfd_arch_powerpc,
 				  dd->endian != KDUMP_LITTLE_ENDIAN,
 				  bfd_mach_ppc, NULL);
+	if (!print_insn)
+		return 0;
 	return disas_at(dd, &info, 0);
 }
diff --git a/ppc64.c b/ppc64.c
index 67a912f..fbfb728 100644
--- a/ppc64.c
+++ b/ppc64.c
@@ -171,5 +171,7 @@ looks_like_kcode_ppc64(struct dump_desc *dd, uint64_t addr)
 	print_insn = disassembler(bfd_arch_powerpc,
 				  dd->endian != KDUMP_LITTLE_ENDIAN,
 				  bfd_mach_ppc64, NULL);
+	if (!print_insn)
+		return 0;
 	return disas_at(dd, &info, 0);
 }
diff --git a/s390.c b/s390.c
index fdd23f7..68c8e5d 100644
--- a/s390.c
+++ b/s390.c
@@ -159,6 +159,8 @@ looks_like_kcode_s390(struct dump_desc *dd, uint64_t addr)
 	disassemble_init_for_target(&info);
 	print_insn = disassembler(bfd_arch_s390, TRUE,
 				  bfd_mach_s390_64, NULL);
+	if (!print_insn)
+		return 0;
 	ret |= disas_at(dd, &info, 0);
 
 	if (ret > 0 && priv.state.flags & SAM64_SEEN)
diff --git a/x86.c b/x86.c
index 5c72bbb..5e35778 100644
--- a/x86.c
+++ b/x86.c
@@ -289,6 +289,7 @@ looks_like_kcode_x86(struct dump_desc *dd, uint64_t addr)
 	print_insn = disassembler(bfd_arch_i386, FALSE,
 				  bfd_mach_i386_i386, NULL);
 	if ((!dd->arch || strcmp(dd->arch, "x86_64")) &&
+	    print_insn &&
 	    disas_at(dd, &info, 0) > 0) {
 		free(priv);
 		return 1;
@@ -301,6 +302,7 @@ looks_like_kcode_x86(struct dump_desc *dd, uint64_t addr)
 	print_insn = disassembler(bfd_arch_i386, FALSE,
 				  bfd_mach_x86_64, NULL);
 	if ((!dd->arch || strcmp(dd->arch, "i386")) &&
+	    print_insn &&
 	    disas_at(dd, &info, 0) > 0) {
 		free(priv);
 		return 1;
-- 
2.39.2


  parent reply	other threads:[~2023-06-28 21:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-28 21:03 [PATCH kdumpid 0/3] Prevent segfault on missing disassembler Stephen Brennan
2023-06-28 21:03 ` [PATCH kdumpid 1/3] cdefs.sh: require bash Stephen Brennan
2023-06-28 21:03 ` [PATCH kdumpid 2/3] Use -lz unconditionally Stephen Brennan
2023-06-28 21:03 ` Stephen Brennan [this message]
2023-06-28 22:12 ` [PATCH kdumpid 0/3] Prevent segfault on missing disassembler Stephen Brennan
2023-06-29  6:26 ` Petr Tesařík

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=20230628210344.357073-4-stephen.s.brennan@oracle.com \
    --to=stephen.s.brennan@oracle.com \
    --cc=linux-debuggers@vger.kernel.org \
    --cc=petr@tesarici.cz \
    /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 NNTP newsgroup(s).