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

Race Condition for Language Target When Formatting with %l #1116

Open
fysiks1 opened this issue Jan 21, 2025 · 0 comments
Open

Race Condition for Language Target When Formatting with %l #1116

fysiks1 opened this issue Jan 21, 2025 · 0 comments

Comments

@fysiks1
Copy link
Contributor

fysiks1 commented Jan 21, 2025

The %l format parameter relies on persistence of the language target set by SetGlobalTransTarget(). However, when this was implemented, it reused an existing global variable. This global variable gets set by several other functions that use it only for temporary purposes (e.g. server_print()). Because of this, it seems that the %l format deserves its own global variable so that client-related print functions can properly use this persisted language target.

Previous discussion in the forums here.

Can be reproduced with the following plugin based on the thread linked above:

#include <amxmodx>

public plugin_init() 
{
	register_dictionary("common.txt")
	register_concmd("testlang", "cmdTest")
}

public cmdTest(id)
{
	SetGlobalTransTarget(id)
	custom_print(id, "%l", "CL_NOT_FOUND");
	log_amx("this is gonna force language change to default");
	custom_print(id, "%l", "CL_NOT_FOUND");

	return PLUGIN_HANDLED
}

custom_print(id, msg[], any:...)
{
	new formattedMsg[MAX_FMT_LENGTH];
	vformat(formattedMsg, charsmax(formattedMsg), msg, 3);
	console_print(id, "%s ^3%s", "[prefix]", formattedMsg);
}

Join the server and set your personal language to a language that does not match the server default language (e.g. if your server default is "en" then run setinfo lang fr). Run testlang in console.

fysiks1 added a commit to fysiks1/amxmodx that referenced this issue Jan 21, 2025
fysiks1 added a commit to fysiks1/amxmodx that referenced this issue Jan 22, 2025
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