diff mbox

[20/23] nfctype5: Discard extra byte in RMB response data

Message ID 20170615182516.4508-21-mgreer@animalcreek.com (mailing list archive)
State Accepted
Delegated to: Samuel Ortiz
Headers show

Commit Message

Mark Greer June 15, 2017, 6:25 p.m. UTC
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>
---
 plugins/nfctype5.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
diff mbox

Patch

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;
 	}