Y-Less / sscanf

SA:MP sscanf plugin originally made by @Y-Less
Other
122 stars 51 forks source link

server crash #35

Closed Dmitriy51 closed 2 years ago

Dmitriy51 commented 3 years ago

f(sscanf(params, "d", player)) return SendClientMessagef(playerid, red,"|USE|: {333333} /ban |id]"); if(!SSCANF_IsConnected(player)) return SendClientMessagef(playerid, red,"|ERROR|: {00FFFF}Player not connected!");

SSCANF_IsConnected(player) this function crash the server, if (player = -11111111111 or player = 11111111111 )

IstuntmanI commented 3 years ago

You have to use the "u" specifier instead of the "d" one. Then, instead of checking for !SSCANF_IsConnected(player), you can simply use player == INVALID_PLAYER_ID. "u" automatically checks for invalid names/IDs in the input and puts INVALID_PLAYER_ID in the required parameter.

If you really want to keep the "d" specifier, so a player name won't be able to be used, the check should probably look like

if(!(0 <= player < MAX_PLAYERS) || !SSCANF_IsConnected(player)) return SendClientMessagef(playerid, red,"|ERROR|: {00FFFF}Player not connected!");
Dmitriy51 commented 3 years ago

You have to use the "u" specifier instead of the "d" one. Then, instead of checking for !SSCANF_IsConnected(player), you can simply use player == INVALID_PLAYER_ID. "u" automatically checks for invalid names/IDs in the input and puts INVALID_PLAYER_ID in the required parameter.

If you really want to keep the "d" specifier, so a player name won't be able to be used, the check should probably look like

if(!(0 <= player < MAX_PLAYERS) || !SSCANF_IsConnected(player)) return SendClientMessagef(playerid, red,"|ERROR|: {00FFFF}Player not connected!");

thaks

Y-Less commented 3 years ago

Why are you calling SSCANF_IsConnected anyway? That's an internal function.

Y-Less commented 2 years ago

I've now hidden this function completely.