Skip to content

Commit 8ea2329

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 27199db commit 8ea2329

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
@@ -464,7 +464,7 @@ int get_fd_type(int fd)
464464
p_err("can't read link type: %s", strerror(errno));
465465
return -1;
466466
}
467-
if (n == sizeof(buf)) {
467+
if (n >= sizeof(buf)) {
468468
p_err("can't read link type: path too long!");
469469
return -1;
470470
}

0 commit comments

Comments
 (0)