sscanf warning: string buffer overflow
#1

Hey guys, I am having a little issue with sscanf, I am making an event admin CMD to set the event info (position, weapons, health etc) and only the position parameter works, all the rest simply do nothing and print a string buffer overflow warning to the console
anyone ?

PHP код:
    if(!strcmp(option"health"true))
    {
        new 
Float:hp;
        if(
sscanf(params"s[10]f"optionhp)) return SendClientMessage(playeridCOLOR_WHITE"USAGE: /seteventinfo health [amount]");
        
EventHealth hp;
        
SendClientMessage(playeridCOLOR_LIGHTBLUE"You have set the new event health amount.");
        return 
1;
    }
    if(!
strcmp(option"armour"true))
    {
        new 
Float:ap;
        if(
sscanf(params[6], "s[10]f"optionap)) return SendClientMessage(playeridCOLOR_WHITE"USAGE: /seteventinfo armour [amount]");
        
EventArmour ap;
        
SendClientMessage(playeridCOLOR_LIGHTBLUE"You have set the new event armour amount.");
        return 
1;
    }
    if(!
strcmp(option"weapon"true))
    {
        new 
slotweaponidammo;
        if(
sscanf(params"s[10]iii"optionslotweaponidammo)) return SendClientMessage(playeridCOLOR_WHITE"USAGE: /seteventinfo weapon [slot] [weapon] [ammo]");
        if(
slot || slot 3) return SendClientMessage(playeridCOLOR_GREY"Slots are between 1 to 3.");
        if(
GetWeaponSlot(weaponid) == -1) return SendClientMessage(playeridCOLOR_WHITE"Invalid weapon ID.");
        if(
ammo 1) return SendClientMessage(playeridCOLOR_GREY"Ammo must be 1 or higher.");
        new 
string[128], weaponname[32];
        
EventWeapon[slot--] = weaponid;
        
EventAmmo[slot--] = ammo;
        
GetWeaponName(weaponidweaponnamesizeof(weaponname));
        
format(stringsizeof(string), "You have set the %d event weapon slot to %s with %d bullets."slotweaponnameammo);
        
SendClientMessage(playeridCOLOR_LIGHTBLUEstring);
        return 
1;
    }
    if(!
strcmp(option"text"true))
    {
        new 
text[80];
        if(
sscanf(params"s[10]s[80]"optiontext)) return SendClientMessage(playeridCOLOR_WHITE"USAGE: /seteventinfo text [text]");
        
format(EventTextsizeof(EventText), "~r~%s"text);
        
SendClientMessage(playeridCOLOR_LIGHTBLUE"You have set the joining event game text.");
        return 
1;
    } 
All those parameters shows nothing IG and warning on the console
Reply
#2

Can you show me the creation of variable 'option'?
+ 'params[6]' - whats that for?
Reply
#3

Quote:
Originally Posted by ranme15
Посмотреть сообщение
Can you show me the creation of variable 'option'?
+ 'params[6]' - whats that for?
params[6] is a tip someone told me to do on the forums, didn't really work so I removed it, forgot to remove it from the armour parameter

Here is the option var
PHP код:
CMD:seteventinfo(playeridparams[])
{
    if(!
IsAllowed(playerid3)) return NoAuth(playerid);
    new 
option[32];
    if(
sscanf(params"s[10]"option))
    {
        
SendClientMessage(playeridCOLOR_WHITE"UASGE: /seteventinfo [option]");
        
SendClientMessage(playeridCOLOR_GREY"Available Options: Health || Armour || Weapon || Position || Text");
        return 
1;
    } 
Reply
#4

Quote:
Originally Posted by NeXoR
Посмотреть сообщение
params[6] is a tip someone told me to do on the forums, didn't really work so I removed it, forgot to remove it from the armour parameter

Here is the option var
PHP код:
CMD:seteventinfo(playeridparams[])
{
    if(!
IsAllowed(playerid3)) return NoAuth(playerid);
    new 
option[32];
    if(
sscanf(params"s[10]"option))
    {
        
SendClientMessage(playeridCOLOR_WHITE"UASGE: /seteventinfo [option]");
        
SendClientMessage(playeridCOLOR_GREY"Available Options: Health || Armour || Weapon || Position || Text");
        return 
1;
    } 
Match the 'option' string size with all the parameters below. (ex. if you've assigned 10 cells, change the [32] to [10])
Reply
#5

Quote:
Originally Posted by ranme15
Посмотреть сообщение
Match the 'option' string size with all the parameters below. (ex. if you've assigned 10 cells, change the [32] to [10])
Same response

When I type
Код:
/seteventinfo health
without any value, it tells me the USAGE message
and when I type
Код:
/seteventinfo health 100
I'm having no response and a warning on the console

Console:
Код:
[CMD] [SaP]Ne[X]oR[R]dT: /seteventinfo health
[CMD] [SaP]Ne[X]oR[R]dT: /seteventinfo health 100
sscanf warning: String buffer overflow.
Reply
#6

increase the string size like this
PHP код:
if(sscanf(params"s[32]"option)) 
    { 
and also you can do a length check to block the processing
Reply
#7

Follow this format:

PHP код:
CMD:seteventinfo(playeridparams[])
{
    if(!
IsAllowed(playerid3)) return NoAuth(playerid); 
    if(
isnull(params))
    {
        
SendClientMessage(playeridCOLOR_WHITE"UASGE: /seteventinfo [option]"); 
        
SendClientMessage(playeridCOLOR_GREY"Available Options: Health || Armour || Weapon || Position || Text"); 
        return 
1
    }
    if (!
strcmp(params"health"true6))
    {
        if (
params[6] != ' ' && params[6] != 0)
        {
            
SendClientMessage(playeridCOLOR_WHITE"UASGE: /seteventinfo [option]"); 
            
SendClientMessage(playeridCOLOR_GREY"Available Options: Health || Armour || Weapon || Position || Text"); 
            return 
1
        }
        new 
Float:hp;
        if (
sscanf(params[7], "f"hp))
            return 
SendClientMessage(playeridCOLOR_WHITE"USAGE: /seteventinfo health [amount]"); 
        
        
EventHealth hp
        
SendClientMessage(playeridCOLOR_LIGHTBLUE"You have set the new event health amount."); 
        return 
1;
    }
    
    if (!
strcmp(params"text"true4)) 
    {
        if (
params[4] != ' ' && params[4] != 0)
        {
            
SendClientMessage(playeridCOLOR_WHITE"UASGE: /seteventinfo [option]"); 
            
SendClientMessage(playeridCOLOR_GREY"Available Options: Health || Armour || Weapon || Position || Text"); 
            return 
1
        }
        new 
text[80]; 
        if (
sscanf(params[5], "s[80]"text)) return SendClientMessage(playeridCOLOR_WHITE"USAGE: /seteventinfo text [text]"); 
        
format(EventTextsizeof(EventText), "~r~%s"text);
        
SendClientMessage(playeridCOLOR_LIGHTBLUE"You have set the joining event game text."); 
        return 
1
    }
    
    
/*
    if (!strcmp(params, "[OPTION]", true, LENGTH OF OPTION))
    {
        if (params[LENGTH OF OPTION] != ' ' && params[LENGTH OF OPTION] != 0)
        {
            SendClientMessage(playerid, COLOR_WHITE, "UASGE: /seteventinfo [option]"); 
            SendClientMessage(playerid, COLOR_GREY, "Available Options: Health || Armour || Weapon || Position || Text"); 
            return 1; 
        }
        Use params[LENGTH OF OPTION + 1] in sscanf
    }
    */
    
return 1;

Reply
#8

Doesn't work mate
Reply
#9

Mine is working fine but there is more variable » French version, apologize ;p
PHP код:
CMD:set(playeridparams[])
{
    if(
pAccount[playerid][pAdmin] < ADMIN) return ErrorMsg(playeridfalse);
    
    new
        
parameter[30 '\0'],
        
scmd[50]; // scmd = subcmd

    
if(sscanf(params"s[30]S()[130]"parameterscmd)) return SCM(playeridLBLUE"/set [money - score - kills - death - skin - vhp - hp - armor - v(irtual)w(orld) - int(erior)]");

    if(!
strcmp(parameter"money"))
    {
        if(
pAccount[playerid][pAdmin] < SADMIN) return ErrorMsg(playeridfalse);

        new 
cible,
            
money;

        if(
sscanf(scmd"ui"ciblemoney)) return SCM(playeridLBLUE"/set money [playerid/name] [montant]");

        if(!
IsPlayerConnected(cible))
            return 
ErrorMsg(playerid_"Cette personne n'est pas connectйe.");

        
ResetPlayerMoney(playerid);
        
GivePlayerMoney(ciblemoney);
        
pAccount[cible][pMoney] = money;
        
SaveSpecificPlayerStats(playerid4);
        if(
money 0
            return 
InfoAnnonce(cible"%i$ on йtй crйditйs sur votre agent de poche."money);
        else
            return 
InfoAnnonce(cible"%i$ ont йtй retirйs de votre argent de poche."0-money);
    }

    else if(!
strcmp(parameter"score"))
    {
        new 
cible,
            
score;

        if(
pAccount[playerid][pAdmin] < SADMIN) return ErrorMsg(playeridfalse);
        
        if(
sscanf(scmd"ui"ciblescore)) return SCM(playeridLBLUE"/set score [playerid/name] [montant]");

        if(!
IsPlayerConnected(cible))
            return 
ErrorMsg(playerid_"Cette personne n'est pas connectйe.");
        
        
SetPlayerScore(cibleGetPlayerScore(cible) + score);
        
pAccount[cible][pScore] = score;
        if(
score 0
            return 
InfoAnnonce(cible"Un administrateur a ajoutй %i а votre score."score);
        else
            return 
InfoAnnonce(cible"Un administrateur a retirй %i а votre score."score);
    }

    else if(!
strcmp(parameter"kills"))
    {
        new 
cible,
            
kills;

        if(
pAccount[playerid][pAdmin] < SADMIN) return ErrorMsg(playeridfalse);
        
        if(
sscanf(scmd"ui"ciblekills)) return SCM(playeridLBLUE"/set kills [playerid/name] [montant]");

        if(!
IsPlayerConnected(cible))
            return 
ErrorMsg(playerid_"Cette personne n'est pas connectйe.");
        
        
pAccount[cible][pKills] += kills;
        if(
kills 0
            return 
InfoAnnonce(cible"Un administrateur a ajoutй %i kills а vos statistiques."kills);
        else
            return 
InfoAnnonce(cible"Un administrateur a retirй %i kills de vos statistiques."kills);
    }

    else if(!
strcmp(parameter"death"))
    {
        new 
cible,
            
death;

        if(
pAccount[playerid][pAdmin] < SADMIN) return ErrorMsg(playeridfalse);
        
        if(
sscanf(scmd"ui"cibledeath)) return SCM(playeridLBLUE"/set death [playerid/name] [montant]");

        if(!
IsPlayerConnected(cible))
            return 
ErrorMsg(playerid_"Cette personne n'est pas connectйe.");
        
        
pAccount[cible][pDeath] += death;
        if(
death 0
            return 
InfoAnnonce(cible"Un administrateur a ajoutй %i morts а vos statistiques."death);
        else
            return 
InfoAnnonce(cible"Un administrateur a retirй %i morts de vos statistiques."death);
    }

    else if(!
strcmp(parameter"skin"))
    {
        new 
cible,
            
skin;

        if(
pAccount[playerid][pAdmin] < MODO) return ErrorMsg(playeridfalse);

        if(
sscanf(scmd"ui"cibleskin)) return SCM(playeridLBLUE"/set skin [playerid/name] [Skinid]");

        if(!
IsPlayerConnected(cible))
            return 
ErrorMsg(playerid_"Cette personne n'est pas connectйe.");

        if(
skin || skin 311
            return 
ErrorMsg(playerid_"Skin invalide! [0-311]");
        
        
pAccount[cible][pSkin] = skin;
        
SetPlayerSkin(cibleskin);
        return 
InfoAnnonce(cible"Votre skin a йtй changй par un administrateur (ID: %i)."skin);
    }

    else if(!
strcmp(parameter"hp") || !strcmp(parameter"health"))
    {
        new 
cible,
            
Float:health;

        if(
pAccount[playerid][pAdmin] < ADMIN) return ErrorMsg(playeridfalse);
    
        if(
sscanf(scmd"if"ciblehealth)) return SCM(playeridLBLUE"/set hp [playerid] [vie]");

        if(!
IsPlayerConnected(cible))
            return 
ErrorMsg(playerid_"Cette personne n'est pas connectйe.");
        
        
SetPlayerHealth(ciblehealth);
        
pAccount[cible][pHealth] = health;
        
SaveSpecificPlayerStats(playerid8);
        
AdminMessage(playerid"Vous avez changй les HP (%0.2f) de %s."healthGetName(cibletrue));
        
InfoAnnonce(cible"Vos points de vies ont йtй changйs par un administrateur.");
        return 
1;
    }

    else if(!
strcmp(parameter"armor") || !strcmp(parameter"ar"))
    {
        new 
cible,
            
Float:armor;

        if(
pAccount[playerid][pAdmin] < ADMIN) return ErrorMsg(playeridfalse);
    
        if(
sscanf(scmd"if"ciblearmor)) return SCM(playeridLBLUE"/set armor [playerid] [armure]");

        if(!
IsPlayerConnected(cible))
            return 
ErrorMsg(playerid_"Cette personne n'est pas connectйe.");
        
        
SetPlayerArmour(ciblearmor);
        
pAccount[cible][pArmor] = armor;
        
AdminMessage(playerid"Vous avez changй l'armure (%0.2f) de %s."armorGetName(cibletrue));
        
InfoAnnonce(cible"Vos points d'armure ont йtй changйs par un administrateur.");
        return 
1;
    }

    else if(!
strcmp(parameter"vhp"))
    {
        new 
vehicleid,
            
Float:health;

        if(
pAccount[playerid][pAdmin] < SADMIN) return ErrorMsg(playeridfalse);
    
        if(
sscanf(scmd"if"vehicleidhealth)) return SCM(playeridLBLUE"/set vhp [vehicleid] [health]");

        if(!
IsValidVehicle(vehicleid))
            return 
ErrorMsg(playerid_"Ce vйhicule est invalide.");
        
        
SetVehicleHealth(vehicleidhealth);
        
vStats[vehicleid][vHealth] = health;
        
AdminMessage(playerid"Vous avez changй les HP (%0.2f) du vйhicule %i."healthvehicleid);
        
AdminCmd("%s a changй les HP (%0.2f) du vйhicule portant l'ID %i"GetName(playerid), healthvehicleid);
        return 
1;
    }

    else if(!
strcmp(parameter"vw") || (!strcmp(parameter"virtualworld")))
    {
        new 
cible,
            
vw;

        if(
pAccount[playerid][pAdmin] < ADMIN) return ErrorMsg(playeridfalse);
    
        if(
sscanf(scmd"ui"ciblevw)) return SCM(playeridLBLUE"/set v(irtual)w(orld) [playerid/nom] [id du monde virtuel]");

        if(!
IsPlayerConnected(cible))
            return 
ErrorMsg(playerid_"Cette personne n'est pas connectйe.");

        
SetPlayerVirtualWorld(ciblevw);
        
pAccount[cible][pVirtualWorld] = vw;
        
AdminMessage(playerid"Vous avez changй le monde virtuel de %s par %i."GetName(cibletrue), vw);
        
InfoAnnonce(cible"Votre monde virtuel a йtй changй par un administrateur.");
        return 
1;
    }

    else if(!
strcmp(parameter"int") || (!strcmp(parameter"interior")))
    {
        new 
cible,
            
int;

        if(
pAccount[playerid][pAdmin] < ADMIN) return ErrorMsg(playeridfalse);
    
        if(
sscanf(scmd"ui"cibleint)) return SCM(playeridLBLUE"/set int(erior) [playerid/nom] [id de l'intйrieur]");

        if(!
IsPlayerConnected(cible))
            return 
ErrorMsg(playerid_"Cette personne n'est pas connectйe.");

        
SetPlayerVirtualWorld(cibleint);
        
pAccount[cible][pInterior] = int;
        
AdminMessage(playerid"Vous avez changй l'intйrieur de %s par %i."GetName(cibletrue), int);
        
InfoAnnonce(cible"L'ID de votre intйrieur a йtй changй par un administrateur.");
        return 
1;
    }

    else return 
ErrorMsg(playerid_"Paramйtre introuvable.");

Reply
#10

Quote:
Originally Posted by NeXoR
Посмотреть сообщение
Doesn't work mate
How does it not work exactly?
Because it should, you're probably doing something wrong.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)