From 2a84e34fb0feff085dcf43eae5de1bf6f8d35d53 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sun, 9 Jul 2023 13:57:01 +0200 Subject: Sanitize tag data, pass dynamic data to commands --- reader.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'reader.c') diff --git a/reader.c b/reader.c index 2c3a06b..32b17f0 100644 --- a/reader.c +++ b/reader.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "nfcommander.h" #include "reader.h" @@ -38,6 +39,21 @@ static struct { nfc_tag_info_t info; } tags[MAX_TAGS] = { 0 }; +static void tag_data_sanitize(nfc_tag_info_t* tag){ + size_t n = 0; + for(n = 0; n < tag->static_length; n++){ + if(tag->static_data[n] && !isprint(tag->static_data[n])){ + tag->static_data[n] = ' '; + } + } + + for(n = 0; n < tag->dynamic_length; n++){ + if(tag->dynamic_data[n] && !isprint(tag->dynamic_data[n])){ + tag->dynamic_data[n] = ' '; + } + } +} + static int reader_init_backend(){ char plugin[MAX_PLUGIN_PATH] = ""; char* reader = config_get("nfc", "reader"); @@ -201,6 +217,7 @@ int reader_tag_present(uint8_t flags, nfc_tag_info_t* tag){ if(flags & TAG_STATUS_FLAGS){ memcpy(&(tags[n].info), tag, sizeof(nfc_tag_info_t)); tags[n].flags |= flags; + tag_data_sanitize(&(tags[n].info)); return 0; } //if data has not yet been fully read, request a full read @@ -209,7 +226,9 @@ int reader_tag_present(uint8_t flags, nfc_tag_info_t* tag){ if(tags[n].flags & (FLAG_WRITE_FULL | FLAG_WRITE_DYNAMIC)){ flags = tags[n].flags; + printf("Requesting %s data write on tag %lu\n", (flags & FLAG_WRITE_FULL) ? "full" : "partial", n); tags[n].flags &= ~(FLAG_WRITE_FULL | FLAG_WRITE_DYNAMIC); + tag_data_sanitize(&(tags[n].info)); //this is kinda dangerous as we hand the reader backend our pointers memcpy(tag, &(tags[n].info), sizeof(nfc_tag_info_t)); -- cgit v1.2.3