Skip to content

Commit

Permalink
core, libctf: Check if constructor arguments are NULL before using them
Browse files Browse the repository at this point in the history
  # pahole
  Segmentation fault (core dumped)
  #

Now we have:

  # ls -la bla
  ls: cannot access 'bla': No such file or directory
  # export PAHOLE_VMLINUX_BTF_FILENAME=bla
  # pahole
  pahole: couldn't find any debug information on this system.
  # pahole list_head
  pahole: couldn't find any debug information on this system.
  # pahole -F btf list_head
  pahole: couldn't find any btf debug information on this system.
  # pahole -F dwarf list_head
  pahole: couldn't find any dwarf debug information on this system.
  #

Reported-by: Matthias Schwarzott <[email protected]>
Reviewed-by: Alan Maguire <[email protected]>
Tested-by: Alan Maguire <[email protected]>
Cc: Andrii Nakryiko <[email protected]>
Cc: Eduard Zingerman <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Song Liu <[email protected]>
Cc: Yonghong Song <[email protected]>
Link: https://lore.kernel.org/all/ZzzY9uwdCO9hezd6@x1
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
acmel committed Nov 19, 2024
1 parent e843385 commit 9374bf4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dwarves.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,9 @@ struct cu *cu__new(const char *name, uint8_t addr_size,
if (cu->use_obstack)
obstack_init(&cu->obstack);

if (name == NULL || filename == NULL)
goto out_free;

cu->name = strdup(name);
if (cu->name == NULL)
goto out_free;
Expand Down
3 changes: 3 additions & 0 deletions libctf.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ struct ctf *ctf__new(const char *filename, Elf *elf)
struct ctf *ctf = zalloc(sizeof(*ctf));

if (ctf != NULL) {
if (filename == NULL)
goto out_delete;

ctf->filename = strdup(filename);
if (ctf->filename == NULL)
goto out_delete;
Expand Down

0 comments on commit 9374bf4

Please sign in to comment.