SA-MP Forums Archive
Variable modified for no reason - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Variable modified for no reason (/showthread.php?tid=589443)



Variable modified for no reason - Vlad64 - 19.09.2015

So, I have this piece of code that's acting weird. The code generates a random 10-character string to be used as a security code, however, a few lines later, a query gets added at the end of it (no idea how... the code variable has a maximum of 10 characters), so the mysql debug query looks like this:

Код:
UPDATE `players` SET `IPCode`='5b2N9UEc9USELECT * FROM `players` WHERE `Name`='Austin' AND `IPCode` IS NULL LIMIT 1' WHERE `Name`='Austin'
Obviously, the query fails to process. The code is 5b2N9UEc9U however, a query a few lines above randomly appears after that, even tho, as I just said, it shouldn't be able to fit at all! Also, for another extremely weird reason, the code itself (without the last U) is put in another place in the database...
This is the code itself:

pawn Код:
new code[10];
randomString(code,10);
format(pInfo[playerid][IPCode],10,"%s",code);
new ipquery[128];
format(ipquery,sizeof(ipquery),"UPDATE `players` SET `IPCode`='%s' WHERE `Name`='%s'",code,playername);
mysql_query(ipquery);
Either it's an extremely easy problem to solve that I just can't see or pawno is drunk... A little help please?


Re: Variable modified for no reason - Vince - 19.09.2015

Buffer overflow. All strings must be zero-terminated. A string of n characters requires a space of n + 1 characters to store the string itself and the null terminator.


Re: Variable modified for no reason - Vlad64 - 19.09.2015

Quote:
Originally Posted by Vince
Посмотреть сообщение
Buffer overflow. All strings must be zero-terminated. A string of n characters requires a space of n + 1 characters to store the string itself and the null terminator.
OH right! I knew about that. That does not however explain why that query was added at the end of it...
Thanks for your quick response!