From 5a1b8bf7bcc9ddd1533735708058d5aecf775641 Mon Sep 17 00:00:00 2001 From: z4yx Date: Sat, 1 Jun 2024 11:42:48 +0800 Subject: [PATCH] fix some warnings and error handling --- applets/ctap/ctap.c | 2 ++ applets/ctap/secret.c | 2 +- interfaces/NFC/fm.c | 2 ++ interfaces/USB/class/webusb/webusb.c | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/applets/ctap/ctap.c b/applets/ctap/ctap.c index 11d9ea6b..1f07d5d3 100644 --- a/applets/ctap/ctap.c +++ b/applets/ctap/ctap.c @@ -702,6 +702,7 @@ static uint8_t ctap_make_credential(CborEncoder *encoder, uint8_t *params, size_ sha256_update(mc.client_data_hash, sizeof(mc.client_data_hash)); sha256_final(data_buf); len = sign_with_device_key(data_buf, PRIVATE_KEY_LENGTH[SECP256R1], data_buf); + if (!len) return CTAP2_ERR_UNHANDLED_REQUEST; ret = cbor_encode_byte_string(&att_map, data_buf, len); CHECK_CBOR_RET(ret); @@ -1154,6 +1155,7 @@ static uint8_t ctap_get_assertion(CborEncoder *encoder, uint8_t *params, size_t DBG_MSG("Message: "); PRINT_HEX(data_buf, len + CLIENT_DATA_HASH_SIZE); len = sign_with_private_key(dc.credential_id.alg_type, &key, data_buf, len + CLIENT_DATA_HASH_SIZE, data_buf); + if (len < 0) return CTAP2_ERR_UNHANDLED_REQUEST; DBG_MSG("Signature: "); PRINT_HEX(data_buf, len); ret = cbor_encode_byte_string(&map, data_buf, len); diff --git a/applets/ctap/secret.c b/applets/ctap/secret.c index a37c3a17..174ac95f 100644 --- a/applets/ctap/secret.c +++ b/applets/ctap/secret.c @@ -334,7 +334,7 @@ int verify_key_handle(const credential_id *kh, ecc_key_t *key) { size_t sign_with_device_key(const uint8_t *input, size_t input_len, uint8_t *sig) { ecc_key_t key; int ret = read_device_pri_key(key.pri); - if (ret < 0) return ret; + if (ret < 0) return 0; ecc_sign(SECP256R1, &key, input, input_len, sig); memzero(&key, sizeof(key)); return ecdsa_sig2ansi(PRI_KEY_SIZE, sig, sig); diff --git a/interfaces/NFC/fm.c b/interfaces/NFC/fm.c index a94c8d44..669f8fb9 100644 --- a/interfaces/NFC/fm.c +++ b/interfaces/NFC/fm.c @@ -18,6 +18,8 @@ uint8_t fm_read_reg(uint16_t reg) { fm_csn_high(); #elif NFC_CHIP == NFC_CHIP_FM11NT fm11nt_read(reg, &val, 1); +#else + val = 0; #endif return val; } diff --git a/interfaces/USB/class/webusb/webusb.c b/interfaces/USB/class/webusb/webusb.c index 51b1c669..61bcca5f 100644 --- a/interfaces/USB/class/webusb/webusb.c +++ b/interfaces/USB/class/webusb/webusb.c @@ -69,7 +69,7 @@ uint8_t USBD_WEBUSB_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { break; case WEBUSB_REQ_STAT: - USBD_CtlSendData(pdev, &state, 1, WEBUSB_EP0_SENDER); + USBD_CtlSendData(pdev, (uint8_t*)&state, 1, WEBUSB_EP0_SENDER); break; default: