Commit graph

957 commits

Author SHA1 Message Date
Philippe Teuwen
d9854cfdd9 Fix out-of-bounds access in driver acr122_pcsc
Problem reported by Coverity:
CID 1091328 (#1 of 1): Out-of-bounds access (OVERRUN)
  overrun-buffer-arg: Overrunning buffer pointed to by "&abtTxBuf[6]" of 271 bytes by passing it to a function which accesses it at byte offset 271 using argument "szData" (which evaluates to 266).
2013-09-22 01:47:15 +02:00
Philippe Teuwen
ddf58f2d69 Changing conditions to avoid Coverity to complain in artificial situations
CID 1090331 (#1 of 1): Out-of-bounds access (OVERRUN)
11. overrun-buffer-arg: Overrunning array "pnti->nai.abtUid" of 10 bytes by passing it to a function which accesses it at byte offset 11 using argument "pnti->nai.szUidLen" (which evaluates to 12).
2013-09-20 00:13:21 +02:00
Philippe Teuwen
a5e7dec797 Initialize array to keep Coverity happy
as Coverity fails seeing that szTargetTypes will always be = 0 in the case believed to lead to reading unitialized data in apttTargetTypes.

CID 1090347 (#1 of 1): Uninitialized scalar variable (UNINIT)
4. uninit_use_in_call: Using uninitialized element of array "apttTargetTypes" when calling "pn53x_InAutoPoll(struct nfc_device *, pn53x_target_type const *, size_t const, uint8_t const, uint8_t const, nfc_target *, int const)".
2013-09-20 00:01:41 +02:00
Philippe Teuwen
30fdf1d9c2 Fix unbounded source buffer
source could be larger than destination

Problem reported by Coverity
CID 1090342 (#1 of 1): Unbounded source buffer (STRING_SIZE)
10. string_size: Passing string "envvar" of unknown size to "strcpy(char * restrict, char const * restrict)", which expects a string of a particular size.
2013-09-19 23:48:44 +02:00
Philippe Teuwen
9240770ab1 acr122s_scan should not return -1 if of type size_t 2013-09-19 23:39:03 +02:00
Philippe Teuwen
3d040d73f3 Fix memory leak
Problems reported by Coverity:

CID 1090335 (#1 of 1): Resource leak (RESOURCE_LEAK)
24. leaked_storage: Variable "acPorts" going out of scope leaks the storage it points to.

CID 1090336 (#1 of 1): Resource leak (RESOURCE_LEAK)
10. leaked_storage: Variable "acPorts" going out of scope leaks the storage it points to.

CID 1090337 (#1 of 1): Resource leak (RESOURCE_LEAK)
21. leaked_storage: Variable "i2cPorts" going out of scope leaks the storage it points to.

CID 1090338 (#1 of 1): Resource leak (RESOURCE_LEAK)
21. leaked_storage: Variable "acPorts" going out of scope leaks the storage it points to.

CID 1090339 (#1 of 1): Resource leak (RESOURCE_LEAK)
23. leaked_storage: Variable "acPorts" going out of scope leaks the storage it points to.
2013-09-19 23:34:52 +02:00
Philippe Teuwen
b6b63f10b4 Fix warning about out-of-bound read
Actually the second part of the condition guaranteed that an out-of-bound read would never occur but now code is neater.
It was:  for (j = 0; (j < "too_large_bound") && (const_ca[i].saklist[j] >= 0); j++)

Problem reported by Coverity
CID 1090332 (#1 of 1): Out-of-bounds read (OVERRUN)
67. overrun-local: Overrunning array "const_ca[i].saklist" of 8 4-byte elements at element index 31 (byte offset 124) using index "j" (which evaluates to 31).
2013-09-19 23:08:06 +02:00
Philippe Teuwen
3e7dab1e8d Fix buffer overflow and fix triple-size UID reported by PN531
A buffer overflow could occur is a triple-size UID card was read with a PN531.
Moreover the way cascade tags were removed was just wrong.

Problem reported by Coverity
CID 1090331 (#1 of 1): Out-of-bounds access (OVERRUN)
10. overrun-buffer-arg: Overrunning buffer pointed to by "&pnti->nai.abtUid[5]" of 10 bytes by passing it to a function which accesses it at byte offset 11 using argument "7UL".

Coverity reported a read out of bounds but actually the real problem if PN531 and triple-size UID will already occur at
    memcpy(pnti->nai.abtUid, pbtRawData, pnti->nai.szUidLen); where abtUid is of size 10 and szUidLen of size 12
2013-09-19 22:57:15 +02:00
Ludovic Rousseau
967f6e5623 Remove dead code
The switch case has a default rule and a return in every cases. So the
code after the switch will never be executed.

Problem reported by thei Coverity tool
CID 1090408 (#1 of 1): Structurally dead code (UNREACHABLE)unreachable:
This code cannot be reached: "if (pn53x_current_target_ne...".
2013-09-19 20:34:58 +02:00
Nobuhiro Iwamatsu
fdcb2c3290 Add support kFreeBSD
kFreeBSD use cuaX as uart device.
This supports the kFreeBSD in Debian, and fix failure to build.

Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@debian.org>
2013-09-10 21:12:59 +02:00
Romuald Conty
ec933731b7 Prepare 1.7.0 version 2013-09-03 16:42:46 +02:00
Peter Meerwald
40672ed62b pn532: fix typo in comment
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2013-09-03 16:31:25 +02:00
Peter Meerwald
733080ba0c uart: fix typo 'eaten'
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2013-09-03 16:31:04 +02:00
Peter Meerwald
0b9fe52b2b pn53x: fix logging, timeout value
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2013-09-03 16:30:01 +02:00
Marcello Morena
98c4eee28f Modified the preamble sent to PN532 via UART from 5 bytes to 16 bytes, to comply with PN532 manual that says to send a "large" preamble in order to wake up the PN532. This is done to solve wakeup timeout problems on some PN532 Breakout Boards. 2013-09-03 16:01:36 +02:00
Philippe Teuwen
f6fff26f0f Fix warning "empty.c:1:0: warning: ISO C forbids an empty translation unit [-pedantic]" 2013-08-29 22:37:23 +02:00
Philippe Teuwen
b52308d071 TypeB ProtocolInfo: limit mask for ISO14443-4 support flag 2013-08-29 22:23:01 +02:00
Ludovic Rousseau
c89532fa19 libnfcbuses.la use at least an empty source file
Closes issue #254: acr122_pcsc compilation failed on Mac OSX 10.8.4
2013-08-29 18:55:55 +02:00
Philippe Teuwen
8fe13ece62 pn53x_initiator_transceive_bytes_timed(): use proper CRC_B if TypeB 2013-08-19 15:47:44 +02:00
Philippe Teuwen
c3a5fba028 Adding iso14443b_crc_append() 2013-08-19 14:55:27 +02:00
Philippe Teuwen
bb5b712a74 Adding link to AUTHORS in the copyright headers 2013-07-17 13:57:56 +02:00
Philippe Teuwen
18fe330413 Fix warning Function call argument is an uninitialized value
acr122_usb.c:237:3: warning: Function call argument is an uninitialized value
  LOG_HEX(NFC_LOG_GROUP_COM, "TX", abtTx, szTx);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../libnfc/log.h:107:7: note: expanded from macro 'LOG_HEX'
      snprintf (__acBuf + __szBuf, sizeof(__acBuf) - __szBuf, "%02x ",((uint8_t *)(pbtData))[__szPos]); \
      ^                                                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Maybe a side effect of the #pragma pack not properly understood by the static analyser
but anyway acr122_usb_frame_template is also used the same way to initialize the other frames
2013-07-03 01:02:18 +02:00
Philippe Teuwen
2db4a0e7e4 make style
new version of astyle, better separation of XOR
2013-07-03 00:16:15 +02:00
Philippe Teuwen
a5d40cefc8 Fix warning about garbage value
acr122s.c:196:23: warning: The left operand of '<<' is a garbage value
  size_t frame_size = FRAME_SIZE(frame);
                      ^          ~~~~~~
acr122s.c:76:24: note: expanded from macro 'FRAME_SIZE'
                       ^
acr122s.c:74:47: note: expanded from macro 'APDU_SIZE'
2013-07-03 00:10:24 +02:00
Philippe Teuwen
5cda3af5d4 Fix warnings Null pointer passed as an argument to a nonnull parameter
acr122s.c:331:3: warning: Null pointer passed as an argument to a 'nonnull' parameter
  memcpy(buf, data, data_size);
  ^           ~~~~

pn53x.c:3138:3: warning: Null pointer passed as an argument to a 'nonnull' parameter
  memcpy(CHIP_DATA(pnd)->current_target, pnt, sizeof(nfc_target));
  ^                                      ~~~
2013-07-02 23:47:45 +02:00
Philippe Teuwen
56e9f1978d Fix warning increasing required alignment
acr122_usb.c:513:20: warning: cast from 'uint8_t *' (aka 'unsigned char *') to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Wcast-align]
  uint32_t *pu32 = (uint32_t *)u8;
                   ^~~~~~~~~~~~~~
2013-07-02 23:11:38 +02:00
Philippe Teuwen
cc7c0c32f1 Fix warning about incompatible types
pn53x.c:85:57: warning: Result of 'malloc' is converted to a pointer of type 'nfc_modulation_type', which is incompatible with sizeof operand type 'nfc_modulation'
    CHIP_DATA(pnd)->supported_modulation_as_initiator = malloc(sizeof(nfc_modulation) * 9);
                                                        ^~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
2013-07-02 22:44:55 +02:00
Mike Auty
ebe6335fc1 Rerun usb_find_busses() and usb_find_devices() without recalling usb_init()
Fixes issue #252
2013-06-22 20:03:45 +02:00
Philippe Teuwen
03e1f23a40 Make use of new PN53x_ACK_FRAME__LEN 2013-06-15 23:14:54 +02:00
Laurent Latil
80a41010fb Fix various problems in I2C support of PN532: - Fix a memory leak in pn532_i2c_wait_rdyframe() - Remove unused parameters and local variables - Fix all other compilation warnings
Note: a new constant (PN53x_ACK_FRAME__LEN) has been defined in
pn53x-internal.h file to avoid hard coding the ACK frame length.
2013-06-15 22:53:35 +02:00
Philippe Teuwen
957bebfd48 make style 2013-06-15 22:51:53 +02:00
Philippe Teuwen
9de66d463b UART: add support for BeagleBone serial ports
Thanks to Johan Henselmans!
2013-06-15 22:01:28 +02:00
Philippe Teuwen
d99bcb79fa I2C: add i2c support to CMake 2013-06-15 00:41:20 +02:00
Philippe Teuwen
77445f1672 I2C: remove unneeded I2C_DRIVERS_ENABLED 2013-06-15 00:20:04 +02:00
Philippe Teuwen
3cd26a18f1 I2C: add Laurent Latil as author 2013-06-15 00:04:06 +02:00
Philippe Teuwen
238be3f068 make style 2013-06-15 00:01:25 +02:00
Laurent Latil
1b11450312 Add I2C protocol support for PN532. 2013-06-14 23:59:46 +02:00
Philippe Teuwen
6038aca7d1 acr122_usb: remove ACR122<>TOUCHATAG model distinction 2013-06-14 23:58:55 +02:00
Philippe Teuwen
c6bda74f44 acr122_usb: ACR122U does not need PCSC Escape anymore
ACR122U:
Through PCSC we couldn't send APDUs to the reader if there was no card
but now that we communicate directly with the reader, we can send APDUs
even if there is no card, so we don't need the Escape mechanism anymore
2013-06-14 23:39:43 +02:00
Philippe Teuwen
c2fa73b404 acr122_usb: retry a few times if init failed 2013-06-14 23:28:03 +02:00
Philippe Teuwen
f0471ebc89 acr122_usb: capture more specifically the expected error SW=637f 2013-06-13 21:01:08 +02:00
Romuald Conty
af7eef0c54 acr122_usb: check received Status Word (Touchatag)
Test if SW1 is 0x61 (means more bytes have to be read) before using SW2 as length.

Update issue 251
The driver now check that Status Word (SW1) is equals to 0x61 (more data available) before using SW2 as length.
If SW is not as expected, it show SW1 and SW2.
2013-06-13 15:56:39 +02:00
Romuald Conty
5757fafe0c acr122_usb: check if received frame is long enough (Touchatag)
This prevents from potential out-of-memory read.
2013-06-13 15:49:48 +02:00
Romain Tartière
0a5199a737 Avoid clash with system's htole32 if it exists.
Fix build on FreeBSD.

Reported by:    Ganael Laplanche
2013-05-20 17:02:24 +02:00
Romain Tartière
c1db25c05b Include <stdlib.h>, required for getenv(3).
Fix build if -Werror is set, avoid coredumping at runtime otherwise.

Reported by:	Ganael Laplanche
2013-05-20 17:01:49 +02:00
Romuald Conty
936210c076 pn53x: only create a current target when at least one have been found. 2013-05-13 09:43:46 +02:00
Philippe Teuwen
41ec6d49f6 Add ISO14443-4 chaining support for RX (MI) 2013-04-28 23:52:15 +02:00
Romuald Conty
b84ac324ff pn532_uart: fix 'operation abort' feature with this driver 2013-04-18 13:49:10 +02:00
Philippe Teuwen
b950eacfdf drivers USB: check usb_open() result
Fixes issue 245
2013-04-05 15:42:57 +02:00
Philippe Teuwen
9cb9e0e6da Fix cppcheck warning: The scope of the variable X can be reduced. 2013-04-05 14:38:03 +02:00