aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Greer <mgreer@animalcreek.com>2017-06-14 09:57:05 -0700
committerSamuel Ortiz <sameo@linux.intel.com>2017-11-10 00:23:57 +0100
commit68bff398cca51195dd5e46fbf361b96ba7030e34 (patch)
treee81427839fadd6d145a1c58cd93619eb9c15ddf4
parentc1e61887d6a83e45362740f6c2ba6871c5c51cf5 (diff)
downloadneard-68bff398cca51195dd5e46fbf361b96ba7030e34.tar.gz
nfctype5: Discard extra byte in RMB response data
Sometimes there can be an extra byte in the response data for Read Multiple Blocks (RMB) commands so discard it whenever that happens. Signed-off-by: Mark Greer <mgreer@animalcreek.com>
-rw-r--r--plugins/nfctype5.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/plugins/nfctype5.c b/plugins/nfctype5.c
index a91d8f5..d6eec3c 100644
--- a/plugins/nfctype5.c
+++ b/plugins/nfctype5.c
@@ -654,7 +654,7 @@ static int t5_read_multiple_blocks_resp(uint8_t *resp, int length, void *data)
uint8_t blk_size = near_tag_get_blk_size(tag);
size_t data_length;
GList *records;
- int err;
+ int err, expected_len;
DBG("");
@@ -665,9 +665,16 @@ static int t5_read_multiple_blocks_resp(uint8_t *resp, int length, void *data)
goto out_done;
length -= NFC_HEADER_SIZE;
+ expected_len = sizeof(*t5_resp) +
+ cookie->nb_requested_blocks * blk_size;
- if (length != (int)(sizeof(*t5_resp) +
- (cookie->nb_requested_blocks * blk_size))) {
+ /*
+ * Sometimes an extra byte is returned in RMB response data.
+ * Discard the extra byte whenever that happens.
+ */
+ if (length == (expected_len + 1)) {
+ length--;
+ } else if (length != expected_len) {
err = -EIO;
goto out_done;
}