Thursday, February 01, 2007

Buffer overflow in C causes terminal to Die?

If it is: Can you imagine how it felt when POS terminal won't run, power ON after application test? Don't think it' s everyday event. You break a microprocessor of a computer, it won't turn on anymore because of lousy handling of memory in C.
For two weeks couldn't get where was the problem, just Balance inquiry transaction won't run, it was making me crazy! After every trial it reset the terminal, printing error stack. There's no syntax errors in the code. Code is ok, can't say great. ISO8583BufLen=1024 was the size of the buffer I declared, somehow 8454 bytes of data coming to the terminal - according to debug printouts. Previously I had just 500 something bytes of data coming after request is sent to the server now it's 8454 bytes or 16 times greater data!
Today went to bank with Poland model terminal, it's not handshaking with the server! So requested the bank terminal for testing. It seemed like data is coming Ok for few transactions. Suddenly it started to behave in unexpected manners. As Tian suggested tried to print out every field I seperated from the incoming packet, no use, can't even reach the statements in the Case switch after receiving the data. So checked the TxnType, it's coming 11629, and 11625 in two trials, it should have been just 5.
Check TxnType before building up my packet, check after sending the packet, check after receiving the packet...........Now I've incoming packet with 515 bytes of data in Balance inquiry. My declarared buffer is 1024, I was not so afraid of the buffer size. But after many hours of struggle Tian pinpointed line 66 #define MAX_COMBUF_SIZE 512 in bankcomm.c. I believe just because of 3 bytes of data memory overflow occured and killed the microprocessor when I tested repeatedly.

If it was not the issue: 1. Power fluctuation killed the Power supply unit. 2. Communication part didn't get uninterrupted connection. But these are unlikely as far as I'm concerned.

Rage against the machine? I hope it's the reason for the irregular Balance inquiry transaction, otherwise more machines will be killed :D
Hope you understood the entry.

No comments: