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

[BUG] A use after free bug in client.c #184

Open
ShangzhiXu opened this issue Mar 31, 2023 · 0 comments
Open

[BUG] A use after free bug in client.c #184

ShangzhiXu opened this issue Mar 31, 2023 · 0 comments

Comments

@ShangzhiXu
Copy link

File: client.c
Bug Function: Client_send_message_except
Version: Git-master


int Client_send_message_except(client_t *client, message_t *msg)
{
	client_t *itr = NULL;
	int count = 0;

	Msg_inc_ref(msg); /* Make sure a reference is held during the whole iteration. */
	while (Client_iterate_authenticated(&itr)) {
		if (itr != client) {
			if (count++ > 0)
				Msg_inc_ref(msg); /* One extra reference for each new copy */
			Log_debug("Msg %d to %s refcount %d",  msg->messageType, itr->username, msg->refcount);
			Client_send_message(itr, msg);
		}
	}
	Msg_free(msg); /* Free our reference to the message */

	if (count == 0)
		Msg_free(msg); /* If only 1 client is connected then no message is passed
						* to Client_send_message(). Free it here. */

	return 0;
}

In this function, if the msg->refcount is zero and the loop while (Client_iterate_authenticated(&itr)) executed zero times, the execute trace would be:

client_t *itr = NULL;
int count = 0;
Msg_inc_ref(msg); 
Msg_free(msg); /* Free our reference to the message */

if (count == 0)
	Msg_free(msg); 

This might lead to a UAF bug as msg was freed and revisited in the second Msg_free(msg);

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

No branches or pull requests

1 participant