LGTM, ack for this patch.
Thanks,
Tao Liu
On Fri, Nov 1, 2024 at 11:01 PM Guanyou Chen <chenguanyou9338(a)gmail.com> wrote:
Hi Lianbo, Tao
When the ELF Note does not contain CPU registers,
attempting to retrieve online CPU registers will cause a crash.
After:
CPU 6:
help: registers not collected for cpu 6
...
Signed-off-by: Guanyou.Chen <chenguanyou(a)xiaomi.com>
---
netdump.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/netdump.c b/netdump.c
index 8ea5159..435793b 100644
--- a/netdump.c
+++ b/netdump.c
@@ -2780,6 +2780,10 @@ display_regs_from_elf_notes(int cpu, FILE *ofp)
nd->nt_prstatus_percpu[cpu];
else
note64 = (Elf64_Nhdr *)nd->nt_prstatus;
+ if (!note64) {
+ error(INFO, "registers not collected for cpu %d\n", cpu);
+ return;
+ }
len = sizeof(Elf64_Nhdr);
len = roundup(len + note64->n_namesz, 4);
len = roundup(len + note64->n_descsz, 4);
@@ -2820,6 +2824,10 @@ display_regs_from_elf_notes(int cpu, FILE *ofp)
nd->nt_prstatus_percpu[cpu];
else
note32 = (Elf32_Nhdr *)nd->nt_prstatus;
+ if (!note32) {
+ error(INFO, "registers not collected for cpu %d\n", cpu);
+ return;
+ }
len = sizeof(Elf32_Nhdr);
len = roundup(len + note32->n_namesz, 4);
len = roundup(len + note32->n_descsz, 4);
@@ -2857,6 +2865,10 @@ display_regs_from_elf_notes(int cpu, FILE *ofp)
else
note64 = (Elf64_Nhdr *)nd->nt_prstatus;
+ if (!note64) {
+ error(INFO, "registers not collected for cpu %d\n", cpu);
+ return;
+ }
prs = (struct ppc64_elf_prstatus *)
((char *)note64 + sizeof(Elf64_Nhdr) + note64->n_namesz);
prs = (struct ppc64_elf_prstatus *)roundup((ulong)prs, 4);
@@ -2903,6 +2915,10 @@ display_regs_from_elf_notes(int cpu, FILE *ofp)
nd->nt_prstatus_percpu[cpu];
else
note64 = (Elf64_Nhdr *)nd->nt_prstatus;
+ if (!note64) {
+ error(INFO, "registers not collected for cpu %d\n", cpu);
+ return;
+ }
len = sizeof(Elf64_Nhdr);
len = roundup(len + note64->n_namesz, 4);
len = roundup(len + note64->n_descsz, 4);
--
2.34.1
Guanyou.
Thanks