AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   name[MAX_NAME_LENGTH] (https://forums.alliedmods.net/showthread.php?t=305561)

emsit 02-24-2018 14:46

name[MAX_NAME_LENGTH]
 
1 Attachment(s)
Hello everyone.

Does it make sense to MAX_NAME_LENGTH be defined at 32?
utf-8 characters use multiple bits. And my plugins crash if the user name contains utf-8 characters...
I give a small example.

output
Test_1: name[MAX_NAME_LENGTH]
strlen: 31, name: '🆃🅴🆂🆃_🅴🅼🆂
Test_2: name[128]
strlen: 37, name: '🆃🅴🆂🆃_🅴🅼🆂🅸🆃'
Test_3: name[MAX_NAME_LENGTH] + remove invalid UTF-8 char
strlen: 29, name: '🆃🅴🆂🆃_🅴🅼🆂'

result
Test_1: Standard use, missing apostroch, plugin crashes
Test_2: ok, no overflow protection.
Test_3: with overflow protection.

what do you think is the best choice to use?

Powerlord 02-24-2018 16:31

Re: name[MAX_NAME_LENGTH]
 
As I recall, it's set to 32 bytes (well... 31 bytes plus nul terminator) because that's the limit in Source games.

emsit 02-24-2018 16:50

Re: name[MAX_NAME_LENGTH]
 
But I think sourcemod works with a longer user name than 32 bytes. (I must test it.)

In any case, the string returned from GetClientName in conjunction with MAX_NAME_LENGTH returns the corrupted string.

Here is an example of a user with the name "████████████████████" (strlen = 60)

PHP Code:

char sName[MAX_NAME_LENGTH];
GetClientName(clientsNamesizeof(sName));

char escaped_name[MAX_NAME_LENGTH 2];
hDatabase.Escape(nameescaped_namesizeof(escaped_name));
FormatEx(querysizeof(query), "INSERT INTO test (server, steamid, name) VALUES ('%s', '%s', '%s');"ServerIPsteamidescaped_name); 

Missing apostrophe at the end!
Code:

L 02/22/2018 - 09:00:58: Query: INSERT INTO test (server, steamid, name) VALUES ('5.196.99.41:27015', '[U:1:XXXXXXXX]', '██████████?);
L 02/22/2018 - 09:00:58: Query failed! Incorrect string value: '\xE2' for column 'name' at row 1


cravenge 02-24-2018 19:51

Re: name[MAX_NAME_LENGTH]
 
I'd go with the second as I use this whenever I collect others' names.
Code:

char sPlayerName[128];

psychonic 02-25-2018 10:17

Re: name[MAX_NAME_LENGTH]
 
What game are you testing it?

In CS:GO, MAX_PLAYER_NAME_LENGTH in the engine is 128 bytes. However, in all other supported games, it's 32 bytes, which can even causes truncation in the engine itself, before SourceMod gets the name. (It looks like your test plugin is for L4D2).

That said, I don't remember if there's any good reason why we didn't increase SM's MAX_NAME_LENGTH to 128, to match CS:GO.

emsit 02-25-2018 14:05

Re: name[MAX_NAME_LENGTH]
 
Hi, my plugin is for L4D2.
I tested it, when I changed my name through "SetClientInfo (client, "name", name);" the name was shortened to 32bytes. So setting the variable to 128bytes will not solve my problem.
The only solution is to check the player name and remove the last invalid UTF-8 char. It's a shame that it sourcemod does not do it automatically.

psychonic 02-25-2018 15:06

Re: name[MAX_NAME_LENGTH]
 
I'm still not fully understanding the issue.

What I do know:
  • A user's name in Steam can be 32 characters, including multi-byte characters.
  • A user's name in L4D2 gets cut off at 32 bytes internally in the engine. (m_Name on CGameClient).
  • This same behavior occurs if you manually set their name.
  • If the above happens, the cut off can be in the middle of a character, causing the corruption you mention.
  • So far, none of the above has anything to do with SourceMod. The engine can have a corrupted name.
When SourceMod first gets the name and when it caches updates to the name, it does attempt to strip off any invalid characters at the end of the name. Using MAX_NAME_LENGTH (32) should never cause further corrupt because the engine already only holds 32 bytes of the name. Regardless, GetClientName should not be able to return a name with a trailing invalid character, unless you are on an old version (SM 1.7 or lower).

emsit 02-26-2018 02:38

Re: name[MAX_NAME_LENGTH]
 
Quote:

Originally Posted by psychonic (Post 2580137)
When SourceMod first gets the name and when it caches updates to the name, it does attempt to strip off any invalid characters at the end of the name.

I suspect that in my case did not remove invalid characters. (https://forums.alliedmods.net/showpo...68&postcount=3)

Code:

sm version
 SourceMod Version Information:
    SourceMod Version: 1.8.0.6040
    SourcePawn Engine: SourcePawn 1.8, jit-x86 (build 1.8.0.6040)
    SourcePawn API: v1 = 4, v2 = 11
    Compiled on: Dec 19 2017 21:30:41
    Built from: https://github.com/alliedmodders/sourcemod/commit/b43ab42
    Build ID: 6040:b43ab42
    http://www.sourcemod.net/

I'm create a simple plugin to test my theory today. I will write you later.

emsit 02-26-2018 11:43

Re: name[MAX_NAME_LENGTH]
 
Steam does not allow me to change my name to something more than 32 bytes.
So I can not test it..

But this problem still exists but is very rare.

Specifically, my bug:
Code:

L 02/22/2018 - 09:00:58: Query: INSERT INTO test (server, steamid, name) VALUES ('5.196.99.41:27015', '[U:1:XXXXXXXX]', '██████████?);
L 02/22/2018 - 09:00:58: Query failed! Incorrect string value: '\xE2' for column 'name' at row 1

was generated by this player who managed to change the username (maybe via api?) to more than 32bytes.
His profile: (name: ████████████████████)
https://steamidfinder.com/lookup/76561198013648641/
http://steamcommunity.com/profiles/76561198013648641

backwards 02-26-2018 11:49

Re: name[MAX_NAME_LENGTH]
 
Quote:

Originally Posted by emsit (Post 2580301)
Steam does not allow me to change my name to something more than 32 bytes.
So I can not test it..

But this problem still exists but is very rare.

Specifically, my bug:
Code:

L 02/22/2018 - 09:00:58: Query: INSERT INTO test (server, steamid, name) VALUES ('5.196.99.41:27015', '[U:1:XXXXXXXX]', '██████████?);
L 02/22/2018 - 09:00:58: Query failed! Incorrect string value: '\xE2' for column 'name' at row 1

was generated by this player who managed to change the username (maybe via api?) to more than 32bytes.
His profile: (name: ████████████████████)
https://steamidfinder.com/lookup/76561198013648641/
http://steamcommunity.com/profiles/76561198013648641


Just a heads up, if they are changing their name like that to something you can't do in steam or console then they most likely are cheating to be able to set their name within the game engine. I'd say that's suspicious enough just to perm ban them. Most people using a cheat/exploit like this aren't only stopping at changing their name and are most likely taking advantage of other stuff hacking related.


All times are GMT -4. The time now is 11:21.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.