From cf92bfaeee801be61906b23c457ed483aed97555 Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Thu, 20 Jan 2011 15:42:46 +0000 Subject: [PATCH] Fix crash when file cannot be opened for writing. --- examples/nfc-mfclassic.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/nfc-mfclassic.c b/examples/nfc-mfclassic.c index cc2b1a6..6462d40 100644 --- a/examples/nfc-mfclassic.c +++ b/examples/nfc-mfclassic.c @@ -494,6 +494,10 @@ main (int argc, const char *argv[]) printf ("Writing data to file: %s ...", argv[3]); fflush (stdout); pfDump = fopen (argv[3], "wb"); + if (pfDump == NULL) { + printf ("Could not open dump file: %s\n", argv[3]); + exit (EXIT_FAILURE); + } if (fwrite (&mtDump, 1, sizeof (mtDump), pfDump) != sizeof (mtDump)) { printf ("\nCould not write to file: %s\n", argv[3]); exit (EXIT_FAILURE); @@ -536,6 +540,10 @@ main (int argc, const char *argv[]) printf ("Writing data to file: %s\n", pcPayload); pfPayload = fopen (pcPayload, "wb"); + if (pfPayload == NULL) { + printf ("Could not open file %s for writting.\n", pcPayload); + exit (EXIT_FAILURE); + } if (fwrite (abPayload, 1, sizeof (abPayload), pfPayload) != sizeof (abPayload)) { printf ("Could not write to file: %s\n", pcPayload); exit (EXIT_FAILURE);