Re: [PATCH bpf-next v4 1/3] bpftool: Add bpf_token show

From: Tao Chen

Date: Mon Sep 15 2025 - 22:17:04 EST


在 2025/9/16 00:21, Andrii Nakryiko 写道:

Hi Andrii, Chris,

On Sat, Sep 13, 2025 at 10:18 AM Chris Mason <clm@xxxxxxxx> wrote:

On Wed, 23 Jul 2025 22:44:40 +0800 Tao Chen <chen.dylane@xxxxxxxxx> wrote:

[ ... ]

diff --git a/tools/bpf/bpftool/token.c b/tools/bpf/bpftool/token.c
new file mode 100644
index 00000000000..6312e662a12
--- /dev/null
+++ b/tools/bpf/bpftool/token.c
@@ -0,0 +1,225 @@

[ ... ]

+
+static char *get_delegate_value(const char *opts, const char *key)
+{
+ char *token, *rest, *ret = NULL;
+ char *opts_copy = strdup(opts);
+
+ if (!opts_copy)
+ return NULL;
+
+ for (token = strtok_r(opts_copy, ",", &rest); token;
+ token = strtok_r(NULL, ",", &rest)) {
+ if (strncmp(token, key, strlen(key)) == 0 &&
+ token[strlen(key)] == '=') {
+ ret = token + strlen(key) + 1;
+ break;
+ }
+ }
+ free(opts_copy);
+
+ return ret;

The ret pointer is pointing inside opts_copy, but opts_copy gets freed
before returning?

Thanks for the bug report, Chris!

Tao, the fix probably should be something along the lines of:

ret = token + strlen(key) + 1 - opts_copy + opts;

to translate that pointer back into the original string? Can you
please send a patch?


Of course, i will fix it, thanks for the bug report.


-chris
--
Best Regards
Tao Chen