From 4b6ba0aa3c3665f3b527aaeacb3db0a4eaace4d7 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 2 Mar 2011 15:02:30 +0000 Subject: [PATCH] Always set the size of Rx buffer (prevent from overflow) --- examples/mifare.c | 2 +- examples/nfc-anticol.c | 2 +- examples/nfc-dep-initiator.c | 2 +- examples/nfc-dep-target.c | 2 +- examples/nfc-emulate-forum-tag4.c | 2 +- examples/nfc-emulate-tag.c | 2 +- examples/pn53x-diagnose.c | 2 +- examples/pn53x-sam.c | 4 ++-- examples/pn53x-tamashell.c | 2 +- libnfc/drivers/arygon.c | 4 ++-- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/mifare.c b/examples/mifare.c index 9fcc47e..6f94420 100644 --- a/examples/mifare.c +++ b/examples/mifare.c @@ -51,7 +51,7 @@ bool nfc_initiator_mifare_cmd (nfc_device_t * pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param * pmp) { byte_t abtRx[265]; - size_t szRx; + size_t szRx = sizeof(abtRx); size_t szParamLen; byte_t abtCmd[265]; bool bEasyFraming; diff --git a/examples/nfc-anticol.c b/examples/nfc-anticol.c index 40d7e68..b6b2f6a 100644 --- a/examples/nfc-anticol.c +++ b/examples/nfc-anticol.c @@ -54,7 +54,7 @@ static byte_t abtRx[MAX_FRAME_LEN]; static size_t szRxBits; -static size_t szRx; +static size_t szRx = sizeof(abtRx); static byte_t abtRawUid[12]; static byte_t abtAtqa[2]; static byte_t abtSak; diff --git a/examples/nfc-dep-initiator.c b/examples/nfc-dep-initiator.c index b2f5006..645ab23 100644 --- a/examples/nfc-dep-initiator.c +++ b/examples/nfc-dep-initiator.c @@ -53,7 +53,7 @@ main (int argc, const char *argv[]) nfc_device_t *pnd; nfc_target_t nt; byte_t abtRx[MAX_FRAME_LEN]; - size_t szRx; + size_t szRx = sizeof(abtRx); byte_t abtTx[] = "Hello World!"; if (argc > 1) { diff --git a/examples/nfc-dep-target.c b/examples/nfc-dep-target.c index 9a74dfa..033120e 100644 --- a/examples/nfc-dep-target.c +++ b/examples/nfc-dep-target.c @@ -50,7 +50,7 @@ int main (int argc, const char *argv[]) { byte_t abtRx[MAX_FRAME_LEN]; - size_t szRx; + size_t szRx = sizeof(abtRx); size_t szDeviceFound; byte_t abtTx[] = "Hello Mars!"; nfc_device_t *pnd; diff --git a/examples/nfc-emulate-forum-tag4.c b/examples/nfc-emulate-forum-tag4.c index 9b5cb39..b2b5235 100644 --- a/examples/nfc-emulate-forum-tag4.c +++ b/examples/nfc-emulate-forum-tag4.c @@ -68,7 +68,7 @@ #define MAX_FRAME_LEN 264 static byte_t abtRx[MAX_FRAME_LEN]; -static size_t szRx; +static size_t szRx = sizeof(abtRx); static nfc_device_t *pnd; static bool quiet_output = false; diff --git a/examples/nfc-emulate-tag.c b/examples/nfc-emulate-tag.c index 9c4935d..bf19e81 100644 --- a/examples/nfc-emulate-tag.c +++ b/examples/nfc-emulate-tag.c @@ -56,7 +56,7 @@ #define SAK_ISO14443_4_COMPLIANT 0x20 static byte_t abtRx[MAX_FRAME_LEN]; -static size_t szRx; +static size_t szRx = sizeof(abtRx); static nfc_device_t *pnd; static bool quiet_output = false; static bool init_mfc_auth = false; diff --git a/examples/pn53x-diagnose.c b/examples/pn53x-diagnose.c index 735f21a..f930d53 100644 --- a/examples/pn53x-diagnose.c +++ b/examples/pn53x-diagnose.c @@ -55,7 +55,7 @@ main (int argc, const char *argv[]) bool result; byte_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; - size_t szRx; + size_t szRx = sizeof(abtRx); const byte_t pncmd_diagnose_communication_line_test[] = { 0xD4, 0x00, 0x00, 0x06, 'l', 'i', 'b', 'n', 'f', 'c' }; const byte_t pncmd_diagnose_rom_test[] = { 0xD4, 0x00, 0x01 }; const byte_t pncmd_diagnose_ram_test[] = { 0xD4, 0x00, 0x02 }; diff --git a/examples/pn53x-sam.c b/examples/pn53x-sam.c index e981dd3..38bb320 100644 --- a/examples/pn53x-sam.c +++ b/examples/pn53x-sam.c @@ -74,7 +74,7 @@ sam_connection (nfc_device_t * pnd, int mode) size_t szCmd = 0; byte_t abtRx[MAX_FRAME_LEN]; - size_t szRx; + size_t szRx = sizeof(abtRx); pncmd_sam_config[2] = mode; @@ -210,7 +210,7 @@ main (int argc, const char *argv[]) case DUAL_CARD_MODE: { byte_t abtRx[MAX_FRAME_LEN]; - size_t szRx; + size_t szRx = sizeof(abtRx); nfc_target_t nt = { .nm = { diff --git a/examples/pn53x-tamashell.c b/examples/pn53x-tamashell.c index 4a0410d..d6df7cf 100644 --- a/examples/pn53x-tamashell.c +++ b/examples/pn53x-tamashell.c @@ -63,7 +63,7 @@ int main(int argc, const char* argv[]) nfc_device_t* pnd; byte_t abtRx[MAX_FRAME_LEN]; byte_t abtTx[MAX_FRAME_LEN] = { 0xD4 }; - size_t szRx; + size_t szRx = sizeof(abtRx); size_t szTx; extern FILE* stdin; FILE* input = NULL; diff --git a/libnfc/drivers/arygon.c b/libnfc/drivers/arygon.c index eb868df..b73e9a8 100644 --- a/libnfc/drivers/arygon.c +++ b/libnfc/drivers/arygon.c @@ -371,7 +371,7 @@ void arygon_ack (const nfc_device_spec_t nds) { byte_t abtRx[BUFFER_LENGTH]; - size_t szRx; + size_t szRx = sizeof(abtRx); #ifdef DEBUG PRINT_HEX ("TX", arygon_ack_frame, sizeof (arygon_ack_frame)); #endif @@ -392,7 +392,7 @@ bool arygon_check_communication (const nfc_device_spec_t nds) { byte_t abtRx[RX_BUFFER_LENGTH]; - size_t szRx; + size_t szRx = sizeof(abtRx); const byte_t attempted_result[] = { 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, // ACK 0x00, 0x00, 0xff, 0x09, 0xf7, 0xd5, 0x01, 0x00, 'l', 'i', 'b', 'n', 'f', 'c', 0xbc, 0x00 }; // Reply int res;