To make sure we don't crash on malformed symbols.

Acked-by: Andrii Nakryiko <andr...@fb.com>
Signed-off-by: Jiri Olsa <jo...@kernel.org>
---
 tools/bpf/resolve_btfids/main.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
index 52d883325a23..b83369887df6 100644
--- a/tools/bpf/resolve_btfids/main.c
+++ b/tools/bpf/resolve_btfids/main.c
@@ -199,9 +199,16 @@ static char *get_id(const char *prefix_end)
        /*
         * __BTF_ID__func__vfs_truncate__0
         * prefix_end =  ^
+        * pos        =    ^
         */
-       char *p, *id = strdup(prefix_end + sizeof("__") - 1);
+       int len = strlen(prefix_end);
+       int pos = sizeof("__") - 1;
+       char *p, *id;
 
+       if (pos >= len)
+               return NULL;
+
+       id = strdup(prefix_end + pos);
        if (id) {
                /*
                 * __BTF_ID__func__vfs_truncate__0
-- 
2.25.4

Reply via email to