Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add lookup_user_record() #1618

Merged
merged 14 commits into from
Jun 29, 2024
Merged

add lookup_user_record() #1618

merged 14 commits into from
Jun 29, 2024

Conversation

vanosg
Copy link
Member

@vanosg vanosg commented Jun 15, 2024

Found by: Mystery-X
Patch by: Geo

It was discovered after the latest rewrite lookup up user records based on account that there are situations where m might not be known, and m being NULL can cause a crash if not properly checked. This creates a wrapper function to a) check which lookup to use based on the provided input, b) fallback to a different lookup in case something returns NULL.

Wrapper function to find an Eggdrop user record based on either a provided
channel memberlist record, host, or account. This function will first check
a provided memberlist and return the result. If no user record is found (or
the memberlist itself was NULL), this function will try again based on a
provided account, and then again on a provided host.

When calling this function it is best to provide all available independent
variables- ie, if you provide 'm' for the memberlist, don't provide
'm->account' for the account, use the independent source variable 'account'
if available. This allows redundant checking in case of unexpected NULLs

@vanosg vanosg added this to the v1.10.0 milestone Jun 15, 2024
src/mod/module.h Show resolved Hide resolved
src/cmds.c Outdated Show resolved Hide resolved
src/mod/irc.mod/chan.c Outdated Show resolved Hide resolved
src/mod/server.mod/servmsg.c Show resolved Hide resolved
@thommey
Copy link
Member

thommey commented Jun 29, 2024

More generally I think I disagree with changing get_user_from_member(m) to lookup_user_record(m, NULL, NULL) or even lookup_user_record(m, NULL, from).
lookup_user_record(m, NULL, from) suggests m could be NULL when in almost all of those cases it can't be.
Using get_user_from_member(m) is less confusing in my opinion when we know m isn't NULL.

The nickname search combination lookup_user_record & check_all_chan_records should be folded into a single thing in my opinion, because it is always used together and is an unnecessary extra step. It could just get a nickname and call get_user_from_member(m) on the first one it finds and return that result.

@vanosg
Copy link
Member Author

vanosg commented Jun 29, 2024

The (m, NULL, NULL) is necessary and only used in cases where host is derived from m. If m doesn't exist, m-> doesn't exist. These cases don't have a 'from' or similar variable to pull the host from.

Copy link
Member Author

@vanosg vanosg left a comment

Choose a reason for hiding this comment

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

should be u2 = lookup_user_record(NULL, NULL, host); ?

@vanosg vanosg merged commit 2fa3042 into develop Jun 29, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants