Skip to content

Commit af91af3

Browse files
RuslanSemchenkoAlexei Starovoitov
authored andcommitted
tools/bpf_jit_disasm: Fix potential negative tpath index in get_exec_path()
If readlink() fails, len will be -1, which can cause negative indexing and undefined behavior. This patch ensures that len is set to 0 on readlink failure, preventing such issues. Signed-off-by: Ruslan Semchenko <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 0e93df4 commit af91af3

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

tools/bpf/bpf_jit_disasm.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ static void get_exec_path(char *tpath, size_t size)
4545
assert(path);
4646

4747
len = readlink(path, tpath, size);
48+
if (len < 0)
49+
len = 0;
4850
tpath[len] = 0;
4951

5052
free(path);

0 commit comments

Comments
 (0)