diff --git a/ccid/src/binutil.c b/ccid/src/binutil.c index ad3f0e6..b180d4e 100644 --- a/ccid/src/binutil.c +++ b/ccid/src/binutil.c @@ -28,6 +28,7 @@ void print_usage(const char *app_name, const struct option options[], printf("Usage: %s [OPTIONS]\nOptions:\n", app_name); while (options[i].name) { + /* Flawfinder: ignore */ char buf[40], tmp[5]; const char *arg_str; @@ -38,6 +39,7 @@ void print_usage(const char *app_name, const struct option options[], } if (options[i].val > 0 && options[i].val < 128) + /* Flawfinder: ignore */ sprintf(tmp, "-%c", options[i].val); else tmp[0] = 0; @@ -52,8 +54,8 @@ void print_usage(const char *app_name, const struct option options[], arg_str = ""; break; } - sprintf(buf, "--%-13s%s%s", options[i].name, tmp, arg_str); - if (strlen(buf) > 24) { + snprintf(buf, sizeof(buf), "--%-13s%s%s", options[i].name, tmp, arg_str); + if (strnlen(buf, sizeof(buf)) > 24) { printf(" %s\n", buf); buf[0] = '\0'; } diff --git a/ccid/src/ccid.c b/ccid/src/ccid.c index 468dd77..3767801 100644 --- a/ccid/src/ccid.c +++ b/ccid/src/ccid.c @@ -331,6 +331,7 @@ get_RDR_to_PC_SlotStatus(__u8 bSlot, __u8 bSeq, int sc_result, __u8 **outbuf, si status->bError = get_bError(sc_result); status->bClockStatus = 0; + /* Flawfinder: ignore */ memcpy((*outbuf) + sizeof(*status), abProtocolDataStructure, abProtocolDataStructureLen); return SC_SUCCESS; @@ -362,6 +363,7 @@ get_RDR_to_PC_DataBlock(__u8 bSlot, __u8 bSeq, int sc_result, __u8 **outbuf, data->bError = get_bError(sc_result); data->bChainParameter = 0; + /* Flawfinder: ignore */ memcpy((*outbuf) + sizeof(*data), abData, abDataLen); return SC_SUCCESS; @@ -848,6 +850,7 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card, sc_result = SC_ERROR_INVALID_ARGUMENTS; goto err; } + /* Flawfinder: ignore */ memcpy(&word, &abData[parsed], sizeof word); pace_input.certificate_description_length = __le16_to_cpu(word); parsed += sizeof word; @@ -892,6 +895,7 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card, dword = __cpu_to_le32(pace_output.result); + /* Flawfinder: ignore */ memcpy(p, &dword, sizeof dword); p += sizeof dword; @@ -902,6 +906,7 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card, 1+pace_output.recent_car_length + 1+pace_output.previous_car_length + 2+pace_output.id_icc_length); + /* Flawfinder: ignore */ memcpy(p, &word, sizeof word); p += sizeof word; @@ -920,9 +925,11 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card, goto err; } word = __cpu_to_le16(pace_output.ef_cardaccess_length); + /* Flawfinder: ignore */ memcpy(p, &word, sizeof word); p += sizeof word; + /* Flawfinder: ignore */ memcpy(p, pace_output.ef_cardaccess, pace_output.ef_cardaccess_length); p += pace_output.ef_cardaccess_length; @@ -937,6 +944,7 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card, *p = pace_output.recent_car_length; p += 1; + /* Flawfinder: ignore */ memcpy(p, pace_output.recent_car, pace_output.recent_car_length); p += pace_output.recent_car_length; @@ -951,6 +959,7 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card, *p = pace_output.previous_car_length; p += 1; + /* Flawfinder: ignore */ memcpy(p, pace_output.previous_car, pace_output.previous_car_length); p += pace_output.previous_car_length; @@ -963,9 +972,11 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card, goto err; } word = __cpu_to_le16(pace_output.id_icc_length); + /* Flawfinder: ignore */ memcpy(p, &word, sizeof word); p += sizeof word; + /* Flawfinder: ignore */ memcpy(p, pace_output.id_icc, pace_output.id_icc_length); p += pace_output.id_icc_length; @@ -1215,9 +1226,9 @@ perform_PC_to_RDR_Secure(const __u8 *in, size_t inlen, __u8** out, size_t *outle } /* set length of PIN */ - curr_pin.len = strlen((char *) curr_pin.data); + curr_pin.len = strnlen((char *) curr_pin.data, curr_pin.max_length); if (modify) { - new_pin.len = strlen((char *) new_pin.data); + new_pin.len = strnlen((char *) new_pin.data, new_pin.max_length); } /* Note: pin.offset and pin.length_offset are relative to the first @@ -1498,6 +1509,7 @@ int ccid_parse_control(struct usb_ctrlrequest *setup, __u8 **outbuf) } *outbuf = tmp; __le32 clock = ccid_desc.dwDefaultClock; + /* Flawfinder: ignore */ memcpy(*outbuf, &clock, sizeof (__le32)); break; @@ -1515,6 +1527,7 @@ int ccid_parse_control(struct usb_ctrlrequest *setup, __u8 **outbuf) } *outbuf = tmp; __le32 drate = ccid_desc.dwDataRate; + /* Flawfinder: ignore */ memcpy(*outbuf, &drate, sizeof (__le32)); break; diff --git a/ccid/src/pace.c b/ccid/src/pace.c index c247484..363607c 100644 --- a/ccid/src/pace.c +++ b/ccid/src/pace.c @@ -441,6 +441,7 @@ static int pace_gen_auth_1_encrypted_nonce(struct sm_ctx *oldpacectx, r = SC_ERROR_OUT_OF_MEMORY; goto err; } + /* Flawfinder: ignore */ memcpy(*enc_nonce, p, l); *enc_nonce_len = l; @@ -555,6 +556,7 @@ static int pace_gen_auth_2_map_nonce(struct sm_ctx *oldpacectx, r = SC_ERROR_OUT_OF_MEMORY; goto err; } + /* Flawfinder: ignore */ memcpy(*map_data_out, p, l); *map_data_out_len = l; @@ -669,6 +671,7 @@ static int pace_gen_auth_3_perform_key_agreement( r = SC_ERROR_OUT_OF_MEMORY; goto err; } + /* Flawfinder: ignore */ memcpy(*eph_pub_key_out, p, l); *eph_pub_key_out_len = l; @@ -787,6 +790,7 @@ static int pace_gen_auth_4_mutual_authentication( r = SC_ERROR_OUT_OF_MEMORY; goto err; } + /* Flawfinder: ignore */ memcpy(*recent_car, r_data->cur_car->data, r_data->cur_car->length); *recent_car_len = r_data->cur_car->length; } else @@ -799,6 +803,7 @@ static int pace_gen_auth_4_mutual_authentication( r = SC_ERROR_OUT_OF_MEMORY; goto err; } + /* Flawfinder: ignore */ memcpy(*prev_car, r_data->prev_car->data, r_data->prev_car->length); *prev_car_len = r_data->prev_car->length; } else @@ -809,6 +814,7 @@ static int pace_gen_auth_4_mutual_authentication( r = SC_ERROR_OUT_OF_MEMORY; goto err; } + /* Flawfinder: ignore */ memcpy(*auth_token_out, p, l); *auth_token_out_len = l; @@ -864,7 +870,7 @@ pace_reset_retry_counter(struct sm_ctx *ctx, sc_card_t *card, free(p); return SC_ERROR_INTERNAL; } - new_len = strlen(p); + new_len = strnlen(p, MAX_PIN_LEN+1); new = p; } @@ -900,6 +906,7 @@ get_psec(sc_card_t *card, const char *pin, size_t length_pin, enum s_type pin_id char *p = NULL; PACE_SEC *r; int sc_result; + /* Flawfinder: ignore */ char buf[MAX_MRZ_LEN > 32 ? MAX_MRZ_LEN : 32]; if (!length_pin || !pin) { @@ -919,7 +926,7 @@ get_psec(sc_card_t *card, const char *pin, size_t length_pin, enum s_type pin_id pace_secret_name(pin_id)); return NULL; } - length_pin = strlen(p); + length_pin = strnlen(p, MAX_MRZ_LEN); pin = p; } @@ -1209,6 +1216,7 @@ int EstablishPACEChannel(struct sm_ctx *oldpacectx, sc_card_t *card, } pace_output->id_icc = p; pace_output->id_icc_length = comp_pub_opp->length; + /* Flawfinder: ignore */ memcpy(pace_output->id_icc, comp_pub_opp->data, comp_pub_opp->length); bin_log(card->ctx, "ID ICC", pace_output->id_icc, pace_output->id_icc_length); @@ -1219,6 +1227,7 @@ int EstablishPACEChannel(struct sm_ctx *oldpacectx, sc_card_t *card, } pace_output->id_pcd = p; pace_output->id_pcd_length = comp_pub->length; + /* Flawfinder: ignore */ memcpy(pace_output->id_pcd, comp_pub->data, comp_pub->length); bin_log(card->ctx, "ID PCD", pace_output->id_pcd, pace_output->id_pcd_length); @@ -1387,6 +1396,7 @@ pace_sm_encrypt(sc_card_t *card, const struct sm_ctx *ctx, goto err; } *enc = p; + /* Flawfinder: ignore */ memcpy(*enc, encbuf->data, encbuf->length); r = encbuf->length; @@ -1430,6 +1440,7 @@ pace_sm_decrypt(sc_card_t *card, const struct sm_ctx *ctx, goto err; } *data = p; + /* Flawfinder: ignore */ memcpy(*data, databuf->data, databuf->length); r = databuf->length; @@ -1474,6 +1485,7 @@ pace_sm_authenticate(sc_card_t *card, const struct sm_ctx *ctx, goto err; } *macdata = p; + /* Flawfinder: ignore */ memcpy(*macdata, macbuf->data, macbuf->length); r = macbuf->length; diff --git a/ccid/src/scutil.c b/ccid/src/scutil.c index b588c29..2fba000 100644 --- a/ccid/src/scutil.c +++ b/ccid/src/scutil.c @@ -193,6 +193,7 @@ void _bin_log(sc_context_t *ctx, int type, const char *file, int line, FILE *f) { /* this is the maximum supported by sc_do_log_va */ + /* Flawfinder: ignore */ char buf[1800]; if (data) diff --git a/ccid/src/sm.c b/ccid/src/sm.c index 0f046da..2af45dd 100644 --- a/ccid/src/sm.c +++ b/ccid/src/sm.c @@ -61,6 +61,7 @@ add_iso_pad(const u8 *data, size_t datalen, int block_size, u8 **padded) return SC_ERROR_OUT_OF_MEMORY; if (*padded != data) + /* Flawfinder: ignore */ memcpy(p, data, datalen); *padded = p; @@ -85,6 +86,7 @@ add_padding(const struct sm_ctx *ctx, const u8 *data, size_t datalen, if (!p) return SC_ERROR_OUT_OF_MEMORY; *padded = p; + /* Flawfinder: ignore */ memcpy(*padded, data, datalen); } return datalen; @@ -173,6 +175,7 @@ static int prefix_buf(u8 prefix, u8 *buf, size_t buflen, u8 **cat) if (*cat == buf) { memmove(p + 1, p, buflen); } else { + /* Flawfinder: ignore */ memcpy(p + 1, buf, buflen); } p[0] = prefix; @@ -407,6 +410,7 @@ static int sm_encrypt(const struct sm_ctx *ctx, sc_card_t *card, goto err; } mac_data = p; + /* Flawfinder: ignore */ memcpy(mac_data + mac_data_len, asn1, asn1_len); mac_data_len += asn1_len; r = add_padding(ctx, mac_data, mac_data_len, &mac_data); @@ -440,6 +444,7 @@ static int sm_encrypt(const struct sm_ctx *ctx, sc_card_t *card, r = SC_ERROR_OUT_OF_MEMORY; goto err; } + /* Flawfinder: ignore */ memcpy((u8 *) sm_apdu->data, sm_data, sm_data_len); sm_apdu->datalen = sm_data_len; sm_apdu->lc = sm_apdu->datalen; @@ -537,6 +542,7 @@ static int sm_decrypt(const struct sm_ctx *ctx, sc_card_t *card, r = SC_ERROR_OUT_OF_MEMORY; goto err; } + /* Flawfinder: ignore */ memcpy(apdu->resp, data, r); apdu->resplen = r; } else {