Re: [PATCH] libbpf: Initialize st_ops->tname with strdup()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Le 21/08/2024 à 08:46, Soma Nakata a écrit :
`tname` is returned by `btf__name_by_offset()` as well as `var_name`,
and these addresses point to strings in the btf. Since their locations
may change while loading the bpf program, using `strdup()` ensures
`tname` is safely stored.

Signed-off-by: Soma Nakata <soma.nakata01@xxxxxxxxx>
---
  tools/lib/bpf/libbpf.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index a3be6f8fac09..ece1f1af2cd4 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1423,7 +1423,7 @@ static int init_struct_ops_maps(struct bpf_object *obj, const char *sec_name,
  		memcpy(st_ops->data,
  		       data->d_buf + vsi->offset,
  		       type->size);
-		st_ops->tname = tname;
+		st_ops->tname = strdup(tname);

Hi,

Should a NULL check be added (as done a few lines above for the [cm]alloc()) and bpf_map__destroy() updated with a zfree(&map->st_ops->tname) ?

CJ

  		st_ops->type = type;
  		st_ops->type_id = type_id;





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux