From f0c88c065514a3f2344e46b40e06eb5dc3d1c004 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 30 Jan 2013 03:13:12 +0000 Subject: improved input validation cleanups git-svn-id: https://svn.spreadspace.org/avr/trunk@106 aa12f405-d877-488e-9caf-2d797e2a1cc7 --- usb-i2c-sl018/tuer-rfid.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'usb-i2c-sl018') diff --git a/usb-i2c-sl018/tuer-rfid.c b/usb-i2c-sl018/tuer-rfid.c index 1f11a93..2c2c3c8 100644 --- a/usb-i2c-sl018/tuer-rfid.c +++ b/usb-i2c-sl018/tuer-rfid.c @@ -188,6 +188,7 @@ uint8_t sl018_cmd_raw(const uint8_t* twi_send_buf, bool wait_for_answer) if(!wait_for_answer) return 0; + memset(twi_recv_buf, 0, sizeof(twi_recv_buf)); _delay_ms(50); if (TWI_StartTransmission(SL018_TWI_ADDR | TWI_ADDRESS_READ,10) == TWI_ERROR_NoError) { @@ -240,22 +241,22 @@ uint8_t sl018_cmd(const uint8_t* twi_send_buf) void flash_keystore_from_stdio(void) { - keyslot_t keyslot; + keyslot_t ks; uint8_t keyslot_pos=0; uint8_t byte_pos=0; fprintf(stdio,"Flashing keys:\n\r"); fflush(stdio); - for(keyslot_pos=0;keyslot_pos0) { - keyslot[byte_pos++]=fgetc(stdio); + while(bytes_received > 0) { + ks[byte_pos++]=fgetc(stdio); bytes_received--; - if (byte_pos == sizeof(keyslot)) { + if (byte_pos == sizeof(ks)) { byte_pos=0; - eeprom_update_block(&keyslot,&keystore[keyslot_pos],sizeof(keyslot)); + eeprom_update_block(&ks,&keystore[keyslot_pos],sizeof(ks)); keyslot_pos++; fputc('.', stdio); fflush(stdio); @@ -270,13 +271,13 @@ void flash_keystore_from_stdio(void) void dump_keystore_to_stdio(void) { - keyslot_t keyslot; + keyslot_t ks; uint8_t keyslot_pos=0; - for(keyslot_pos=0;keyslot_posdata[sizeof(twi_recv_msg->data) - 1] = 0; fprintf(stdio, "%s\n\r",twi_recv_msg->data); + } break; case '4': //turn cardreader led off if(!sl018_cmd(SL018_CMD_ComRedLedOff)) -- cgit v1.2.3