From e1a2b0225f4d7d63d8aeacb67b789528a6b8ad98 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Fri, 6 Dec 2013 15:24:08 +0100 Subject: [PATCH] Check if nfc_init() returns a valid context This fixes a potential segfault when libnfc is not correctly initialized --- src/mfoc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mfoc.c b/src/mfoc.c index 4f792c0..0cb917d 100644 --- a/src/mfoc.c +++ b/src/mfoc.c @@ -582,6 +582,10 @@ void mf_init(mfreader *r) { // Connect to the first NFC device nfc_init(&context); + if (context == NULL) { + ERR("Unable to init libnfc (malloc)"); + exit(EXIT_FAILURE); + } r->pdi = nfc_open(context, NULL); if (!r->pdi) { printf("No NFC device found.\n");