Commit graph

1923 commits

Author SHA1 Message Date
Philippe Teuwen
a4f466df06 Verify return of nfc_device_set_property_bool()
Problem reported by Coverity:
CID 1090325 (#1 of 1): Unchecked return value (CHECKED_RETURN)
  unchecked_value: No check of the return value of "nfc_device_set_property_bool(pnd, NP_AUTO_ISO14443_4, false)".
2013-09-22 02:41:11 +02:00
Philippe Teuwen
e2135dbaa5 pn53x-sam: fix truncated stdio return value
Problem reported by Coverity:
CID 1090318 (#1 of 1): Truncated stdio return value (CHAR_IO)
char_io: Assigning the return value of "getchar(void)" to char "input" truncates its value
2013-09-22 02:38:17 +02:00
Philippe Teuwen
679897d0a1 nfc-emulate-forum-tag4: fix TOCTOU
Hopefully fix TOCTOU by calling fopen() before stat()

At least this should prevent Coverity to complain about it:
CID 1090346 (#1 of 1): Time of check time of use (TOCTOU)
  fs_check_call: Calling function "stat(char const *, struct stat *)" to perform check on "filename".
  toctou: Calling function "fopen(char const * restrict, char const * restrict)" that uses "filename" after a check function. This can cause a time-of-check, time-of-use race condition.

Note that it seems pretty hard to avoid completely:
https://en.wikipedia.org/wiki/Time_of_check_to_time_of_use#Preventing_TOCTTOU
2013-09-22 02:29:07 +02:00
Philippe Teuwen
feb5f37aa3 nfc-read-forum-tag3: remove redundant error
switch case was redundant as getopt was already telling the issue:

  nfc-read-forum-tag3: option requires an argument -- 'o'
  Option -o requires an argument.

This fixes also a problem reported by Coverity about missing break:

CID 1090330 (#1 of 1): Missing break in switch (MISSING_BREAK)
  unterminated_case: This case (value 63) is not terminated by a 'break' statement.
2013-09-22 02:14:08 +02:00
Philippe Teuwen
70048a0b2c uart.c: check return of read()
Fix warning
uart.c:146:3: warning: ignoring return value of 'read', declared with attribute warn_unused_result [-Wunused-result]

Also reported by Coverity:
CID undefined (#1 of 1): Ignoring number of bytes read (CHECKED_RETURN)
  check_return: "read(int, void *, size_t)" returns the number of bytes read, but it is ignored.
2013-09-22 02:06:58 +02:00
Philippe Teuwen
b5d76a327d Fix strcpy into fixed size buffer in conf.c
Problem reported by Coverity:

CID 1090340 (#1 of 2): Copy into fixed size buffer (STRING_OVERFLOW)
  fixed_size_dest: You might overrun the 256 byte fixed-size string "context->user_defined_devices[context->user_defined_device_count - 1U].name" by copying "value" without checking the length.
  parameter_as_source: Note: This defect has an elevated risk because the source argument is a parameter of the current function.
CID 1090340 (#2 of 2): Copy into fixed size buffer (STRING_OVERFLOW)[select issue]
2013-09-22 01:57:58 +02:00
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
d9b531f50f Verify return of nfc_device_set_property_bool()
Problem reported by Coverity
CID 1090319 (#1 of 1): Unchecked return value (CHECKED_RETURN)
  unchecked_value: No check of the return value of "nfc_device_set_property_bool(pnd, NP_EASY_FRAMING, nt.nti.nai.btSak & 0x20)".
CID 1090320 (#1 of 1): Unchecked return value (CHECKED_RETURN)
  unchecked_value: No check of the return value of "nfc_device_set_property_bool(dev, NP_HANDLE_CRC, false)".
CID 1090324 (#1 of 2): Unchecked return value (CHECKED_RETURN)
  unchecked_value: No check of the return value of "nfc_device_set_property_bool(pnd, NP_ACTIVATE_FIELD, true)".
CID 1090325 (#1 of 1): Unchecked return value (CHECKED_RETURN)
  unchecked_value: No check of the return value of "nfc_device_set_property_bool(pnd, NP_AUTO_ISO14443_4, false)".
2013-09-22 01:31:45 +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
107b4ece8b Fix use after free bug
nfc_exit(context); was called 2 times

CID 1090348 (#1 of 1): Use after free (USE_AFTER_FREE)53. deref_arg:
Calling "nfc_exit(nfc_context *)" dereferences freed pointer "context".
(The dereference is assumed on the basis of the 'nonnull' parameter
attribute.)
2013-09-19 20:38:56 +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
Philippe Teuwen
3a8db49a83 Remove debian/ now that there is an official inclusion in Debian 2013-09-11 00:00:43 +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
Philippe Teuwen
70f6c24ebb Debian: fix Vcs-Git URL 2013-09-10 20:51:51 +02:00
Philippe Teuwen
ad9694cf00 nfc-list: New option to choose which technologies to poll for
This is useful especially against chips emulating several types
at once (e.g. PN53x, PN544 etc)
2013-09-09 15:58:07 +02:00
Ludovic Rousseau
dcb7d137c1 Fix watch file
Using the example at https://wiki.debian.org/debian/watch
2013-09-07 13:22:28 +02:00
Philippe Teuwen
c227e375ae Debian: 1.7.0~rc7 -> 1.7.0 2013-09-03 21:40:19 +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
34bf7b3089 nfs-list: drop outdated examples superseeded by connection string
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2013-09-03 16:30:43 +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
Romuald Conty
bcd479a5d2 Update ChangeLog and NEWS 2013-09-03 15:57:12 +02:00
Ludovic Rousseau
565134d4c4 Add missing \n in a printf() 2013-08-31 17:59:24 +02:00
Philippe Teuwen
a2a335e3d4 make style 2013-08-31 17:35:41 +02:00
Adam Laurie
07c54cd91b allow setting of UID for special 'chinese' ultralight cards 2013-08-31 16:15:27 +01: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
Nobuhiro Iwamatsu
f1b4c8e7c2 Add entry for 1.7.0~rc7-1
Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@debian.org>
2013-08-29 19:11:52 +02:00
Nobuhiro Iwamatsu
6f90560fa9 Remove unnecessary changelog
Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@debian.org>
2013-08-29 19:10:00 +02:00
Ludovic Rousseau
f889de514b Fix symbols file contains debian revision
Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@debian.org>
2013-08-29 19:09:33 +02:00
Ludovic Rousseau
e24d730644 Use bzip2 instead of gzip compression algorithm
The libnfc-1.7.0-rc7.tar.bz2 file is 25% smaller than the equivalent
libnfc-1.7.0-rc7.tar.gz file.
2013-08-29 19:04:04 +02:00
Ludovic Rousseau
f8d2d178d5 Use automake option subdir-objects
Fix for:
examples/Makefile.am:79: warning: source file
'doc/quick_start_example1.c' is in a subdirectory,
examples/Makefile.am:79: but option 'subdir-objects' is disabled
2013-08-29 18:59:41 +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