Friday, August 22, 2008

Got overrun by Buffer overflow!

That was a newbie mistake. I was implementing dynamic mesh grouping and vendor/waypoing calculation logic for javascript (the complicated calculation needs to be done in native code, javascript would be too slow). After exporting a large calculated vendor waypoints to javascript, program hungs on access violation error. In debug mode the error happens upon program return from a function call.

Initially I thought it is javascript error, I was trying out with JS_SetProperty, and I thought to myself maybe I should use JS_DefineProperty instead? No luck. After some tries I found if I reduce the number of elements set in JS_SetElement call, the problem goes away. That was a big hint and I started to suspect the UI has some buffer problems. Sure enough, my rastly written UI code was using a buffer of size 1024, and doing _tscpy WITHOUT proper protection! I know that was bad for a veteran engineer to do that, but it was only an amature project with very limited development time (Still big slap on me). I spend 1 hour on this with majority of time debugging and suspecting the ability of memory management of javascript, all because I saved 10 minutes of my time initially to avoid buffer checking.

Make this a lesson to all fresh engineers/coder, don't cut corners.

1 comment:

Exanimo said...

OMG! What a noob you've been!!! Seriously.. you've lost me at mistake :P
Still surprised it's possible to use bots in Wow, would make some tedious tasks simpler i suppose... just seems to be so much risk at using them, don't dare to put my account on the line for it. :S