From 222ba1838ca4a4ccd9a073feaec5ff20ea2eb444 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Fri, 6 Dec 2013 15:22:42 +0100 Subject: [PATCH] Display right message when no tag is detected This fixes a potential segfault due to an access to uninitialised memory variable access --- src/mfoc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/mfoc.c b/src/mfoc.c index 9c3e615..4f792c0 100644 --- a/src/mfoc.c +++ b/src/mfoc.c @@ -204,10 +204,13 @@ int main(int argc, char *const argv[]) for (i=0;!nfc_initiator_select_passive_target(r.pdi, nm, NULL, 0, &t.nt) && i < 10; i++) zsleep (100); */ - // mf_select_tag(r.pdi, &(t.nt)); - if (nfc_initiator_select_passive_target(r.pdi, nm, NULL, 0, &t.nt) < 0) { + int tag_count; + if ((tag_count = nfc_initiator_select_passive_target(r.pdi, nm, NULL, 0, &t.nt)) < 0) { nfc_perror(r.pdi, "nfc_initiator_select_passive_target"); goto error; + } else if (tag_count == 0) { + ERR("No tag found."); + goto error; } // Test if a compatible MIFARE tag is used