Skip to content

Commit 7015d3d

Browse files
kaushlenKernel Patches Daemon
authored andcommitted
tools/bpf/bpftool: fix buffer handling in get_fd_type()
The current check "if (n == sizeof(buf))" is incorrect for detecting buffer overflow from readlink(). When readlink() fills the entire buffer, it returns sizeof(buf) but does not null-terminate the string, leading to potential buffer overrun in subsequent string operations. Fix by changing the condition to "n >= sizeof(buf)" to properly detect when the buffer is completely filled, ensuring space is reserved for null termination. Signed-off-by: Kaushlendra Kumar <[email protected]>
1 parent 4e70ac0 commit 7015d3d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tools/bpf/bpftool/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ int get_fd_type(int fd)
466466
p_err("can't read link type: %s", strerror(errno));
467467
return -1;
468468
}
469-
if (n == sizeof(buf)) {
469+
if (n >= sizeof(buf)) {
470470
p_err("can't read link type: path too long!");
471471
return -1;
472472
}

0 commit comments

Comments
 (0)