SA-MP Forums Archive
sscanf - string buffer overflow - 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: sscanf - string buffer overflow (/showthread.php?tid=576327)



sscanf - string buffer overflow - Finn707 - 03.06.2015

I know what this warning means, but I shouldn't be getting it.

In an /ame command:
pawn Код:
new action[500];
if(sscanf(params, "s[500]", action))
I know it shouldn't be 500, it should be 124 (which I got from 128 - 5 ("/ame ") and + the null terminator) but I changed it to 500 to see if it actually was a problem with the string length being too small.

However, I still get "sscanf warning: String buffer overflow.", I tested how many characters it takes to set off the warning and it's as soon as I type anything above "/ame iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii". So anything over 97 characters.
(ignore the space in the i's, no idea why the forums added that but I can't get rid of it)

Does anyone know why this is?


Re: sscanf - string buffer overflow - Evocator - 03.06.2015

You are not even allowed to use sccanf with the s specifier only, its completely wrong as ****** did say that and its so obvious why. Use the isnull function instead to detect if the string is empty and then use params rather than action.


Re: sscanf - string buffer overflow - Vince - 03.06.2015

Are you sure that it is caused by this instance of sscanf? Perhaps your functions calls another function that also uses sscanf? Even though using sscanf for strings is quite redundant (as Ralfie said) it should actually work.


Re: sscanf - string buffer overflow - Finn707 - 03.06.2015

Yeah that makes complete sense, I should've thought of that, I would imagine what I'm doing would work though. I remember there was a ton of documentation on ******' GitHub I think but obviously that's gone now so I'm just working off of some of the restored topics, but yeah it makes sense that there's no use for sscanf here.

And yeah Vince, I checked for that but the only functions that are getting called after the sscanf check are format, SetPlayerChatBubble and SendClientMessage.