fix a few cppcheck warnings

This commit is contained in:
Philippe Teuwen committed 2023-09-07 22:28:37 +02:00
1 parent d97f417ee6
commit 3aeb5c493f
13 files changed
+44 -41

No files matched your search

+13 -13
View File
@@ -28,8 +28,8 @@
#include "util.h"
#include "util_posix.h"
#include "iso7816/iso7816core.h"
#include "stddef.h"
#include "stdbool.h"
#include <stddef.h>
#include <stdbool.h>
#include "mifare.h"
#include <stdlib.h>
#include <string.h>
@@ -59,10 +59,10 @@ uint8_t aid[] = { 0x4f, 0x53, 0x45, 0x2e, 0x56, 0x41, 0x53, 0x2e, 0x30, 0x31 };
uint8_t getVasUrlOnlyP2 = 0x00;
uint8_t getVasFullReqP2 = 0x01;
static int ParseSelectVASResponse(uint8_t *response, size_t resLen, bool verbose) {
static int ParseSelectVASResponse(const uint8_t *response, size_t resLen, bool verbose) {
struct tlvdb *tlvRoot = tlvdb_parse_multi(response, resLen);
struct tlvdb *versionTlv = tlvdb_find_full(tlvRoot, 0x9F21);
const struct tlvdb *versionTlv = tlvdb_find_full(tlvRoot, 0x9F21);
if (versionTlv == NULL) {
tlvdb_free(tlvRoot);
return PM3_ECARDEXCHANGE;
@@ -80,7 +80,7 @@ static int ParseSelectVASResponse(uint8_t *response, size_t resLen, bool verbose
return PM3_ECARDEXCHANGE;
}
struct tlvdb *capabilitiesTlv = tlvdb_find_full(tlvRoot, 0x9F23);
const struct tlvdb *capabilitiesTlv = tlvdb_find_full(tlvRoot, 0x9F23);
if (capabilitiesTlv == NULL) {
tlvdb_free(tlvRoot);
return PM3_ECARDEXCHANGE;
@@ -99,7 +99,7 @@ static int ParseSelectVASResponse(uint8_t *response, size_t resLen, bool verbose
return PM3_SUCCESS;
}
static int CreateGetVASDataCommand(uint8_t *pidHash, const char *url, size_t urlLen, uint8_t *out, int *outLen) {
static int CreateGetVASDataCommand(const uint8_t *pidHash, const char *url, size_t urlLen, uint8_t *out, int *outLen) {
if (pidHash == NULL && url == NULL) {
PrintAndLogEx(FAILED, "Must provide a Pass Type ID or a URL");
return PM3_EINVARG;
@@ -154,10 +154,10 @@ static int CreateGetVASDataCommand(uint8_t *pidHash, const char *url, size_t url
return PM3_SUCCESS;
}
static int ParseGetVASDataResponse(uint8_t *res, size_t resLen, uint8_t *cryptogram, size_t *cryptogramLen) {
static int ParseGetVASDataResponse(const uint8_t *res, size_t resLen, uint8_t *cryptogram, size_t *cryptogramLen) {
struct tlvdb *tlvRoot = tlvdb_parse_multi(res, resLen);
struct tlvdb *cryptogramTlvdb = tlvdb_find_full(tlvRoot, 0x9F27);
const struct tlvdb *cryptogramTlvdb = tlvdb_find_full(tlvRoot, 0x9F27);
if (cryptogramTlvdb == NULL) {
tlvdb_free(tlvRoot);
return PM3_ECARDEXCHANGE;
@@ -171,10 +171,10 @@ static int ParseGetVASDataResponse(uint8_t *res, size_t resLen, uint8_t *cryptog
return PM3_SUCCESS;
}
static int LoadReaderPrivateKey(uint8_t *buf, size_t bufLen, mbedtls_ecp_keypair *privKey) {
static int LoadReaderPrivateKey(const uint8_t *buf, size_t bufLen, mbedtls_ecp_keypair *privKey) {
struct tlvdb *derRoot = tlvdb_parse_multi(buf, bufLen);
struct tlvdb *privkeyTlvdb = tlvdb_find_full(derRoot, 0x04);
const struct tlvdb *privkeyTlvdb = tlvdb_find_full(derRoot, 0x04);
if (privkeyTlvdb == NULL) {
tlvdb_free(derRoot);
return PM3_EINVARG;
@@ -187,7 +187,7 @@ static int LoadReaderPrivateKey(uint8_t *buf, size_t bufLen, mbedtls_ecp_keypair
return PM3_EINVARG;
}
struct tlvdb *pubkeyCoordsTlvdb = tlvdb_find_full(derRoot, 0x03);
const struct tlvdb *pubkeyCoordsTlvdb = tlvdb_find_full(derRoot, 0x03);
if (pubkeyCoordsTlvdb == NULL) {
tlvdb_free(derRoot);
PrintAndLogEx(FAILED, "Private key file should include public key component");
@@ -229,7 +229,7 @@ static int GetPrivateKeyHint(mbedtls_ecp_keypair *privKey, uint8_t *keyHint) {
return PM3_SUCCESS;
}
static int LoadMobileEphemeralKey(uint8_t *xcoordBuf, mbedtls_ecp_keypair *pubKey) {
static int LoadMobileEphemeralKey(const uint8_t *xcoordBuf, mbedtls_ecp_keypair *pubKey) {
uint8_t compressedEcKey[33] = {0};
compressedEcKey[0] = 0x02;
memcpy(compressedEcKey + 1, xcoordBuf, 32);
@@ -249,7 +249,7 @@ static int LoadMobileEphemeralKey(uint8_t *xcoordBuf, mbedtls_ecp_keypair *pubKe
static int internalVasDecrypt(uint8_t *cipherText, size_t cipherTextLen, uint8_t *sharedSecret,
uint8_t *ansiSharedInfo, size_t ansiSharedInfoLen,
uint8_t *gcmAad, size_t gcmAadLen, uint8_t *out, size_t *outLen) {
const uint8_t *gcmAad, size_t gcmAadLen, uint8_t *out, size_t *outLen) {
uint8_t key[32] = {0};
if (ansi_x963_sha256(sharedSecret, 32, ansiSharedInfo, ansiSharedInfoLen, sizeof(key), key)) {
PrintAndLogEx(FAILED, "ANSI X9.63 key derivation failed");