From 98a67bc908980d93328a4436a1e5fd2a4ace16f7 Mon Sep 17 00:00:00 2001 From: pwpiwi Date: Mon, 11 May 2020 14:46:22 +0200 Subject: [PATCH] Fix some printf/scanf format strings --- armsrc/iso14443a.c | 4 +++- client/cmdhw.c | 4 ++-- client/emv/emv_tags.c | 2 +- client/fido/cbortools.c | 12 +++--------- client/fpga_compress.c | 4 ++-- client/util.c | 3 ++- client/whereami.c | 2 +- common/fpga.h | 2 +- tools/mfkey/mfkey32.c | 18 +++++++++--------- tools/mfkey/mfkey64.c | 10 +++++----- 10 files changed, 29 insertions(+), 32 deletions(-) diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index 0de5ea6f..8686cea7 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -14,6 +14,8 @@ #include #include +#include + #include "proxmark3.h" #include "apps.h" #include "util.h" @@ -192,7 +194,7 @@ void iso14a_set_trigger(bool enable) { void iso14a_set_timeout(uint32_t timeout) { // adjust timeout by FPGA delays and 2 additional ssp_frames to detect SOF iso14a_timeout = timeout + (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER)/(16*8) + 2; - if(MF_DBGLEVEL >= 3) Dbprintf("ISO14443A Timeout set to %ld (%dms)", timeout, timeout / 106); + if (MF_DBGLEVEL >= 3) Dbprintf("ISO14443A Timeout set to %" PRIu32 " (%dms)", timeout, timeout / 106); } diff --git a/client/cmdhw.c b/client/cmdhw.c index b6a0d11f..b7fa874d 100644 --- a/client/cmdhw.c +++ b/client/cmdhw.c @@ -335,10 +335,10 @@ int CmdFPGAOff(const char *Cmd) int CmdLCD(const char *Cmd) { - int i, j; + unsigned int i, j; UsbCommand c={CMD_LCD}; - sscanf(Cmd, "%x %d", &i, &j); + sscanf(Cmd, "%x %u", &i, &j); while (j--) { c.arg[0] = i & 0x1ff; SendCommand(&c); diff --git a/client/emv/emv_tags.c b/client/emv/emv_tags.c index eed77e76..0dc63517 100644 --- a/client/emv/emv_tags.c +++ b/client/emv/emv_tags.c @@ -400,7 +400,7 @@ static void emv_tag_dump_numeric(const struct tlv *tlv, const struct emv_tag *ta static void emv_tag_dump_yymmdd(const struct tlv *tlv, const struct emv_tag *tag, FILE *f, int level) { PRINT_INDENT(level); - fprintf(f, "\tDate: 20%02ld.%ld.%ld\n", + fprintf(f, "\tDate: 20%02lu.%lu.%lu\n", emv_value_numeric(tlv, 0, 2), emv_value_numeric(tlv, 2, 4), emv_value_numeric(tlv, 4, 6)); diff --git a/client/fido/cbortools.c b/client/fido/cbortools.c index 4674afc9..6cddabfa 100644 --- a/client/fido/cbortools.c +++ b/client/fido/cbortools.c @@ -40,7 +40,7 @@ static CborError dumpelm(CborValue *it, bool *got_next, int nestingLevel) { case CborIntegerType: { int64_t val; cbor_value_get_int64(it, &val); // can't fail - printf("%lld", (long long)val); + printf("%" PRIi64, val); break; } @@ -71,7 +71,7 @@ static CborError dumpelm(CborValue *it, bool *got_next, int nestingLevel) { case CborTagType: { CborTag tag; cbor_value_get_tag(it, &tag); - printf("Tag(%lld)", (long long)tag); + printf("Tag(%" PRIu64, tag); break; } @@ -206,13 +206,7 @@ int TinyCborPrintFIDOPackage(uint8_t cmdCode, bool isResponse, uint8_t *data, si CborError err = dumprecursive(cmdCode, isResponse, &cb, false, 0); if (err) { - fprintf(stderr, -#if __WORDSIZE == 64 - "CBOR parsing failure at offset %" PRId64 " : %s\n", -#else - "CBOR parsing failure at offset %" PRId32 " : %s\n", -#endif - cb.ptr - data, cbor_error_string(err)); + fprintf(stderr, "CBOR parsing failure at offset %td : %s\n", cb.ptr - data, cbor_error_string(err)); return 1; } diff --git a/client/fpga_compress.c b/client/fpga_compress.c index 418a02b8..31b51cdb 100644 --- a/client/fpga_compress.c +++ b/client/fpga_compress.c @@ -99,9 +99,9 @@ int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile, bool hardn if (i >= num_infiles * (hardnested_mode?HARDNESTED_TABLE_SIZE:FPGA_CONFIG_SIZE)) { if (hardnested_mode) { - fprintf(stderr, "Input file too big (> %lu bytes). This is probably not a hardnested bitflip state table.\n", HARDNESTED_TABLE_SIZE); + fprintf(stderr, "Input file too big (> %zu bytes). This is probably not a hardnested bitflip state table.\n", HARDNESTED_TABLE_SIZE); } else { - fprintf(stderr, "Input files too big (total > %lu bytes). These are probably not PM3 FPGA config files.\n", num_infiles*FPGA_CONFIG_SIZE); + fprintf(stderr, "Input files too big (total > %zu bytes). These are probably not PM3 FPGA config files.\n", num_infiles*FPGA_CONFIG_SIZE); } for(uint16_t j = 0; j < num_infiles; j++) { fclose(infile[j]); diff --git a/client/util.c b/client/util.c index 4e93b8f5..20580448 100644 --- a/client/util.c +++ b/client/util.c @@ -11,6 +11,7 @@ #include "util.h" #include +#include #include #include #include @@ -572,7 +573,7 @@ int param_gethex_to_eol(const char *line, int paramnum, uint8_t * data, int maxd } if (strlen(buf) >= 2) { - sscanf(buf, "%x", &temp); + sscanf(buf, "%" SCNx32, &temp); data[*datalen] = (uint8_t)(temp & 0xff); *buf = 0; (*datalen)++; diff --git a/client/whereami.c b/client/whereami.c index 6e5e85f3..28277584 100644 --- a/client/whereami.c +++ b/client/whereami.c @@ -261,7 +261,7 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) if (!fgets(buffer, sizeof(buffer), maps)) break; - if (sscanf(buffer, "%" SCNx64 "-%" SCNx64 " %s %" SCNx64 " %x:%x %u %s\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8) + if (sscanf(buffer, "%" SCNx64 "-%" SCNx64 " %s %" SCNx64 " %" SCNx32 ":%" SCNx32 " %" SCNu32 " %s\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8) { uint64_t addr = (uint64_t)(uintptr_t)WAI_RETURN_ADDRESS(); if (low <= addr && addr <= high) diff --git a/common/fpga.h b/common/fpga.h index 65268ecf..e2acc1ec 100644 --- a/common/fpga.h +++ b/common/fpga.h @@ -9,7 +9,7 @@ #define FPGA_BITSTREAM_FIXED_HEADER_SIZE sizeof(bitparse_fixed_header) #define FPGA_INTERLEAVE_SIZE 288 -#define FPGA_CONFIG_SIZE 42336L // our current fpga_[lh]f.bit files are 42175 bytes. Rounded up to next multiple of FPGA_INTERLEAVE_SIZE +#define FPGA_CONFIG_SIZE ((size_t)42336) // our current fpga_[lh]f.bit files are 42175 bytes. Rounded up to next multiple of FPGA_INTERLEAVE_SIZE #define FPGA_TRACE_SIZE 3072 static const uint8_t bitparse_fixed_header[] = {0x00, 0x09, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x00, 0x00, 0x01}; diff --git a/tools/mfkey/mfkey32.c b/tools/mfkey/mfkey32.c index 1f7747b5..eb2f24c1 100755 --- a/tools/mfkey/mfkey32.c +++ b/tools/mfkey/mfkey32.c @@ -25,18 +25,18 @@ int main (int argc, char *argv[]) { bool moebius_attack = (argc == 8); - sscanf(argv[1],"%x",&data.cuid); - sscanf(argv[2],"%x",&data.nonce); + sscanf(argv[1],"%" SCNx32, &data.cuid); + sscanf(argv[2],"%" SCNx32, &data.nonce); data.nonce2 = data.nonce; - sscanf(argv[3],"%x",&data.nr); - sscanf(argv[4],"%x",&data.ar); + sscanf(argv[3],"%" SCNx32, &data.nr); + sscanf(argv[4],"%" SCNx32, &data.ar); if (moebius_attack) { - sscanf(argv[5],"%x",&data.nonce2); - sscanf(argv[6],"%x",&data.nr2); - sscanf(argv[7],"%x",&data.ar2); + sscanf(argv[5],"%" SCNx32, &data.nonce2); + sscanf(argv[6],"%" SCNx32, &data.nr2); + sscanf(argv[7],"%" SCNx32, &data.ar2); } else { - sscanf(argv[5],"%x",&data.nr2); - sscanf(argv[6],"%x",&data.ar2); + sscanf(argv[5],"%" SCNx32, &data.nr2); + sscanf(argv[6],"%" SCNx32, &data.ar2); } printf("Recovering key for:\n"); diff --git a/tools/mfkey/mfkey64.c b/tools/mfkey/mfkey64.c index 8bf1d801..c8837c7e 100755 --- a/tools/mfkey/mfkey64.c +++ b/tools/mfkey/mfkey64.c @@ -28,11 +28,11 @@ int main (int argc, char *argv[]) int enclen[encc]; uint8_t enc[encc][120]; - sscanf(argv[1], "%x", &uid); - sscanf(argv[2], "%x", &nt); - sscanf(argv[3], "%x", &nr_enc); - sscanf(argv[4], "%x", &ar_enc); - sscanf(argv[5], "%x", &at_enc); + sscanf(argv[1], "%" SCNx32, &uid); + sscanf(argv[2], "%" SCNx32, &nt); + sscanf(argv[3], "%" SCNx32, &nr_enc); + sscanf(argv[4], "%" SCNx32, &ar_enc); + sscanf(argv[5], "%" SCNx32, &at_enc); for (int i = 0; i < encc; i++) { enclen[i] = strlen(argv[i + 6]) / 2; for (int i2 = 0; i2 < enclen[i]; i2++) { -- 2.39.5