Commit 90704b4b authored by Manu Bretelle's avatar Manu Bretelle Committed by Daniel Borkmann

bpftool: Fix printing of pointer value

When printing a pointer value, "%p" will either print the hexadecimal
value of the pointer (e.g `0x1234`), or `(nil)` when NULL.

Both of those are invalid json "integer" values and need to be wrapped
in quotes.

Before:
```
$ sudo bpftool struct_ops dump  name ned_dummy_cca | grep next
                    "next": (nil),
$ sudo bpftool struct_ops dump  name ned_dummy_cca | \
    jq '.[1].bpf_struct_ops_tcp_congestion_ops.data.list.next'
parse error: Invalid numeric literal at line 29, column 34
```

After:
```
$ sudo ./bpftool struct_ops dump  name ned_dummy_cca | grep next
                    "next": "(nil)",
$ sudo ./bpftool struct_ops dump  name ned_dummy_cca | \
    jq '.[1].bpf_struct_ops_tcp_congestion_ops.data.list.next'
"(nil)"
```
Signed-off-by: default avatarManu Bretelle <chantr4@gmail.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Tested-by: default avatarEduard Zingerman <eddyz87@gmail.com>
Acked-by: default avatarEduard Zingerman <eddyz87@gmail.com>
Acked-by: default avatarQuentin Monnet <quentin@isovalent.com>
Link: https://lore.kernel.org/bpf/20231018230133.1593152-2-chantr4@gmail.com
parent 0e133a13
......@@ -127,7 +127,7 @@ static void btf_dumper_ptr(const struct btf_dumper *d,
print_ptr_value:
if (d->is_plain_text)
jsonw_printf(d->jw, "%p", (void *)value);
jsonw_printf(d->jw, "\"%p\"", (void *)value);
else
jsonw_printf(d->jw, "%lu", value);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment