summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2020-08-25 21:21:11 +0200
committerAlexei Starovoitov <ast@kernel.org>2020-08-25 15:37:41 -0700
commit193a983c5bc4c62f66d62a9a6f9084cf3f2a0db2 (patch)
tree7d495677e76d509c4b3d16904e07e913ed7c0a3f
parent2532f849b5134c4c62a20e5aaca33d9fb08af528 (diff)
downloadlinux-193a983c5bc4c62f66d62a9a6f9084cf3f2a0db2.tar.bz2
tools resolve_btfids: Add size check to get_id function
To make sure we don't crash on malformed symbols. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Andrii Nakryiko <andriin@fb.com> Link: https://lore.kernel.org/bpf/20200825192124.710397-2-jolsa@kernel.org
-rw-r--r--tools/bpf/resolve_btfids/main.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
index 4d9ecb975862..35a172d3d80d 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