From 079db13938c0c208bfefaf0201363977ec5f6fa7 Mon Sep 17 00:00:00 2001 From: Ondrej Mikle Date: Tue, 28 Dec 2021 22:38:05 +0100 Subject: [PATCH] Fix race condition when card is removed during read and libfreefare returns list of just NULL pointer --- nfc_smartcard.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nfc_smartcard.cpp b/nfc_smartcard.cpp index 8a04328..930b8fb 100644 --- a/nfc_smartcard.cpp +++ b/nfc_smartcard.cpp @@ -165,6 +165,10 @@ std::string NFCDevice::readDesfireNDEF() throw(NFCError) if (!tags) { throw NFCError("No tags detected"); } + // freefare_get_tags() returns a NULL-terminated list of MifareTag + if (!*tags) { + throw NFCError("Empty array tag, bailing out"); + } MifareTag& tag = *tags; //only first one is used if (DESFIRE != freefare_get_tag_type (tag)) {