[PATCH kdumpid 3/3] Gracefully handle missing dissasembler function

Stephen Brennan <[email protected]>
Newsgroups org.kernel.vger.linux-debuggers
Message-ID <[email protected]>
If disassembler() returns NULL then kdumpid is guaranteed to segfault.
Gracefully return a 0 so we can continue on.

Signed-off-by: Stephen Brennan <[email protected]>
---
 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.