Skip to content

[linux] fix segfault when eventpoll fdinfo is unavailable - #368

Open
daeho-ro wants to merge 1 commit into
lsof-org:masterfrom
daeho-ro:fix-eventpoll-tfd-count-sentinel
Open

[linux] fix segfault when eventpoll fdinfo is unavailable#368
daeho-ro wants to merge 1 commit into
lsof-org:masterfrom
daeho-ro:fix-eventpoll-tfd-count-sentinel

Conversation

@daeho-ro

Copy link
Copy Markdown

tfd_count is declared size_t (dproc.c:97), but process_id() uses -1 as its "no fdinfo" sentinel (dproc.c:1222). It becomes SIZE_MAX, so the fi.tfd_count > 0 guard passes where the != -1 siblings skip, and snp_eventpoll() qsorts SIZE_MAX entries of a 32-entry array:

#4  __GI___qsort_r (total_elems=18446744073709551615, size=4, cmp=fd_compare)
#5  process_id ()

This hits any run with OffType != OFFSET_FDINFO that reports a process holding an epoll descriptor. Declaring it int matches tfds[] and the eventfd_id/pid sentinels.

process_id() pre-fills -1 sentinels for the oty == 0 case, but tfd_count is size_t, so -1 becomes SIZE_MAX and the `fi.tfd_count > 0` guard passes where the `!= -1` siblings skip. snp_eventpoll() then qsorts SIZE_MAX entries of a 32-entry array. Declare it int, matching tfds[], the snp_eventpoll() parameters and the eventfd_id/pid sentinels.
#define EPOLL_MAX_TFDS 32
int tfds[EPOLL_MAX_TFDS];
size_t tfd_count;
int tfd_count;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ssize_t is better? Then the struct size is unchanged, so the ABI is compatible.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try once I have a time 🫡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants