Skip to content

Commit

Permalink
libbf: Fix uninitialized pointer at btf__parse_raw()
Browse files Browse the repository at this point in the history
Recently, from commit 94a1fed ("libbpf: Add btf__parse_raw() and
generic btf__parse() APIs"), new API has been added to libbpf that
allows to parse BTF from raw data file (btf__parse_raw()).

The commit derives build failure of samples/bpf due to improper access
of uninitialized pointer at btf_parse_raw().

    btf.c: In function btf__parse_raw:
    btf.c:625:28: error: btf may be used uninitialized in this function
      625 |  return err ? ERR_PTR(err) : btf;
          |         ~~~~~~~~~~~~~~~~~~~^~~~~

This commit fixes the build failure of samples/bpf by adding code of
initializing btf pointer as NULL.

Fixes: 94a1fed ("libbpf: Add btf__parse_raw() and generic btf__parse() APIs")
Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20200805223359.32109-1-danieltimlee@gmail.com
  • Loading branch information
Daniel T. Lee authored and Alexei Starovoitov committed Aug 6, 2020
1 parent 0ac10dc commit 932ac54
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tools/lib/bpf/btf.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,8 @@ struct btf *btf__parse_elf(const char *path, struct btf_ext **btf_ext)

struct btf *btf__parse_raw(const char *path)
{
struct btf *btf = NULL;
void *data = NULL;
struct btf *btf;
FILE *f = NULL;
__u16 magic;
int err = 0;
Expand Down

0 comments on commit 932ac54

Please sign in to comment.