reviewed files with flawfinder

git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@316 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
frankmorgner
2010-10-11 11:56:18 +00:00
parent 76cb2ee0c6
commit a552631872
5 changed files with 40 additions and 6 deletions

View File

@@ -28,6 +28,7 @@ void print_usage(const char *app_name, const struct option options[],
printf("Usage: %s [OPTIONS]\nOptions:\n", app_name); printf("Usage: %s [OPTIONS]\nOptions:\n", app_name);
while (options[i].name) { while (options[i].name) {
/* Flawfinder: ignore */
char buf[40], tmp[5]; char buf[40], tmp[5];
const char *arg_str; 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) if (options[i].val > 0 && options[i].val < 128)
/* Flawfinder: ignore */
sprintf(tmp, "-%c", options[i].val); sprintf(tmp, "-%c", options[i].val);
else else
tmp[0] = 0; tmp[0] = 0;
@@ -52,8 +54,8 @@ void print_usage(const char *app_name, const struct option options[],
arg_str = ""; arg_str = "";
break; break;
} }
sprintf(buf, "--%-13s%s%s", options[i].name, tmp, arg_str); snprintf(buf, sizeof(buf), "--%-13s%s%s", options[i].name, tmp, arg_str);
if (strlen(buf) > 24) { if (strnlen(buf, sizeof(buf)) > 24) {
printf(" %s\n", buf); printf(" %s\n", buf);
buf[0] = '\0'; buf[0] = '\0';
} }

View File

@@ -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->bError = get_bError(sc_result);
status->bClockStatus = 0; status->bClockStatus = 0;
/* Flawfinder: ignore */
memcpy((*outbuf) + sizeof(*status), abProtocolDataStructure, abProtocolDataStructureLen); memcpy((*outbuf) + sizeof(*status), abProtocolDataStructure, abProtocolDataStructureLen);
return SC_SUCCESS; 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->bError = get_bError(sc_result);
data->bChainParameter = 0; data->bChainParameter = 0;
/* Flawfinder: ignore */
memcpy((*outbuf) + sizeof(*data), abData, abDataLen); memcpy((*outbuf) + sizeof(*data), abData, abDataLen);
return SC_SUCCESS; return SC_SUCCESS;
@@ -848,6 +850,7 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card,
sc_result = SC_ERROR_INVALID_ARGUMENTS; sc_result = SC_ERROR_INVALID_ARGUMENTS;
goto err; goto err;
} }
/* Flawfinder: ignore */
memcpy(&word, &abData[parsed], sizeof word); memcpy(&word, &abData[parsed], sizeof word);
pace_input.certificate_description_length = __le16_to_cpu(word); pace_input.certificate_description_length = __le16_to_cpu(word);
parsed += sizeof 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); dword = __cpu_to_le32(pace_output.result);
/* Flawfinder: ignore */
memcpy(p, &dword, sizeof dword); memcpy(p, &dword, sizeof dword);
p += 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.recent_car_length +
1+pace_output.previous_car_length + 1+pace_output.previous_car_length +
2+pace_output.id_icc_length); 2+pace_output.id_icc_length);
/* Flawfinder: ignore */
memcpy(p, &word, sizeof word); memcpy(p, &word, sizeof word);
p += sizeof word; p += sizeof word;
@@ -920,9 +925,11 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card,
goto err; goto err;
} }
word = __cpu_to_le16(pace_output.ef_cardaccess_length); word = __cpu_to_le16(pace_output.ef_cardaccess_length);
/* Flawfinder: ignore */
memcpy(p, &word, sizeof word); memcpy(p, &word, sizeof word);
p += sizeof word; p += sizeof word;
/* Flawfinder: ignore */
memcpy(p, pace_output.ef_cardaccess, memcpy(p, pace_output.ef_cardaccess,
pace_output.ef_cardaccess_length); pace_output.ef_cardaccess_length);
p += 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 = pace_output.recent_car_length;
p += 1; p += 1;
/* Flawfinder: ignore */
memcpy(p, pace_output.recent_car, memcpy(p, pace_output.recent_car,
pace_output.recent_car_length); pace_output.recent_car_length);
p += 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 = pace_output.previous_car_length;
p += 1; p += 1;
/* Flawfinder: ignore */
memcpy(p, pace_output.previous_car, memcpy(p, pace_output.previous_car,
pace_output.previous_car_length); pace_output.previous_car_length);
p += 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; goto err;
} }
word = __cpu_to_le16(pace_output.id_icc_length); word = __cpu_to_le16(pace_output.id_icc_length);
/* Flawfinder: ignore */
memcpy(p, &word, sizeof word); memcpy(p, &word, sizeof word);
p += sizeof word; p += sizeof word;
/* Flawfinder: ignore */
memcpy(p, pace_output.id_icc, memcpy(p, pace_output.id_icc,
pace_output.id_icc_length); pace_output.id_icc_length);
p += 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 */ /* 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) { 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 /* 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; *outbuf = tmp;
__le32 clock = ccid_desc.dwDefaultClock; __le32 clock = ccid_desc.dwDefaultClock;
/* Flawfinder: ignore */
memcpy(*outbuf, &clock, sizeof (__le32)); memcpy(*outbuf, &clock, sizeof (__le32));
break; break;
@@ -1515,6 +1527,7 @@ int ccid_parse_control(struct usb_ctrlrequest *setup, __u8 **outbuf)
} }
*outbuf = tmp; *outbuf = tmp;
__le32 drate = ccid_desc.dwDataRate; __le32 drate = ccid_desc.dwDataRate;
/* Flawfinder: ignore */
memcpy(*outbuf, &drate, sizeof (__le32)); memcpy(*outbuf, &drate, sizeof (__le32));
break; break;

View File

@@ -441,6 +441,7 @@ static int pace_gen_auth_1_encrypted_nonce(struct sm_ctx *oldpacectx,
r = SC_ERROR_OUT_OF_MEMORY; r = SC_ERROR_OUT_OF_MEMORY;
goto err; goto err;
} }
/* Flawfinder: ignore */
memcpy(*enc_nonce, p, l); memcpy(*enc_nonce, p, l);
*enc_nonce_len = 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; r = SC_ERROR_OUT_OF_MEMORY;
goto err; goto err;
} }
/* Flawfinder: ignore */
memcpy(*map_data_out, p, l); memcpy(*map_data_out, p, l);
*map_data_out_len = 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; r = SC_ERROR_OUT_OF_MEMORY;
goto err; goto err;
} }
/* Flawfinder: ignore */
memcpy(*eph_pub_key_out, p, l); memcpy(*eph_pub_key_out, p, l);
*eph_pub_key_out_len = 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; r = SC_ERROR_OUT_OF_MEMORY;
goto err; goto err;
} }
/* Flawfinder: ignore */
memcpy(*recent_car, r_data->cur_car->data, r_data->cur_car->length); memcpy(*recent_car, r_data->cur_car->data, r_data->cur_car->length);
*recent_car_len = r_data->cur_car->length; *recent_car_len = r_data->cur_car->length;
} else } else
@@ -799,6 +803,7 @@ static int pace_gen_auth_4_mutual_authentication(
r = SC_ERROR_OUT_OF_MEMORY; r = SC_ERROR_OUT_OF_MEMORY;
goto err; goto err;
} }
/* Flawfinder: ignore */
memcpy(*prev_car, r_data->prev_car->data, r_data->prev_car->length); memcpy(*prev_car, r_data->prev_car->data, r_data->prev_car->length);
*prev_car_len = r_data->prev_car->length; *prev_car_len = r_data->prev_car->length;
} else } else
@@ -809,6 +814,7 @@ static int pace_gen_auth_4_mutual_authentication(
r = SC_ERROR_OUT_OF_MEMORY; r = SC_ERROR_OUT_OF_MEMORY;
goto err; goto err;
} }
/* Flawfinder: ignore */
memcpy(*auth_token_out, p, l); memcpy(*auth_token_out, p, l);
*auth_token_out_len = l; *auth_token_out_len = l;
@@ -864,7 +870,7 @@ pace_reset_retry_counter(struct sm_ctx *ctx, sc_card_t *card,
free(p); free(p);
return SC_ERROR_INTERNAL; return SC_ERROR_INTERNAL;
} }
new_len = strlen(p); new_len = strnlen(p, MAX_PIN_LEN+1);
new = p; 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; char *p = NULL;
PACE_SEC *r; PACE_SEC *r;
int sc_result; int sc_result;
/* Flawfinder: ignore */
char buf[MAX_MRZ_LEN > 32 ? MAX_MRZ_LEN : 32]; char buf[MAX_MRZ_LEN > 32 ? MAX_MRZ_LEN : 32];
if (!length_pin || !pin) { 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)); pace_secret_name(pin_id));
return NULL; return NULL;
} }
length_pin = strlen(p); length_pin = strnlen(p, MAX_MRZ_LEN);
pin = p; 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 = p;
pace_output->id_icc_length = comp_pub_opp->length; pace_output->id_icc_length = comp_pub_opp->length;
/* Flawfinder: ignore */
memcpy(pace_output->id_icc, comp_pub_opp->data, comp_pub_opp->length); memcpy(pace_output->id_icc, comp_pub_opp->data, comp_pub_opp->length);
bin_log(card->ctx, "ID ICC", pace_output->id_icc, bin_log(card->ctx, "ID ICC", pace_output->id_icc,
pace_output->id_icc_length); 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 = p;
pace_output->id_pcd_length = comp_pub->length; pace_output->id_pcd_length = comp_pub->length;
/* Flawfinder: ignore */
memcpy(pace_output->id_pcd, comp_pub->data, comp_pub->length); memcpy(pace_output->id_pcd, comp_pub->data, comp_pub->length);
bin_log(card->ctx, "ID PCD", pace_output->id_pcd, bin_log(card->ctx, "ID PCD", pace_output->id_pcd,
pace_output->id_pcd_length); pace_output->id_pcd_length);
@@ -1387,6 +1396,7 @@ pace_sm_encrypt(sc_card_t *card, const struct sm_ctx *ctx,
goto err; goto err;
} }
*enc = p; *enc = p;
/* Flawfinder: ignore */
memcpy(*enc, encbuf->data, encbuf->length); memcpy(*enc, encbuf->data, encbuf->length);
r = encbuf->length; r = encbuf->length;
@@ -1430,6 +1440,7 @@ pace_sm_decrypt(sc_card_t *card, const struct sm_ctx *ctx,
goto err; goto err;
} }
*data = p; *data = p;
/* Flawfinder: ignore */
memcpy(*data, databuf->data, databuf->length); memcpy(*data, databuf->data, databuf->length);
r = databuf->length; r = databuf->length;
@@ -1474,6 +1485,7 @@ pace_sm_authenticate(sc_card_t *card, const struct sm_ctx *ctx,
goto err; goto err;
} }
*macdata = p; *macdata = p;
/* Flawfinder: ignore */
memcpy(*macdata, macbuf->data, macbuf->length); memcpy(*macdata, macbuf->data, macbuf->length);
r = macbuf->length; r = macbuf->length;

View File

@@ -193,6 +193,7 @@ void _bin_log(sc_context_t *ctx, int type, const char *file, int line,
FILE *f) FILE *f)
{ {
/* this is the maximum supported by sc_do_log_va */ /* this is the maximum supported by sc_do_log_va */
/* Flawfinder: ignore */
char buf[1800]; char buf[1800];
if (data) if (data)

View File

@@ -61,6 +61,7 @@ add_iso_pad(const u8 *data, size_t datalen, int block_size, u8 **padded)
return SC_ERROR_OUT_OF_MEMORY; return SC_ERROR_OUT_OF_MEMORY;
if (*padded != data) if (*padded != data)
/* Flawfinder: ignore */
memcpy(p, data, datalen); memcpy(p, data, datalen);
*padded = p; *padded = p;
@@ -85,6 +86,7 @@ add_padding(const struct sm_ctx *ctx, const u8 *data, size_t datalen,
if (!p) if (!p)
return SC_ERROR_OUT_OF_MEMORY; return SC_ERROR_OUT_OF_MEMORY;
*padded = p; *padded = p;
/* Flawfinder: ignore */
memcpy(*padded, data, datalen); memcpy(*padded, data, datalen);
} }
return datalen; return datalen;
@@ -173,6 +175,7 @@ static int prefix_buf(u8 prefix, u8 *buf, size_t buflen, u8 **cat)
if (*cat == buf) { if (*cat == buf) {
memmove(p + 1, p, buflen); memmove(p + 1, p, buflen);
} else { } else {
/* Flawfinder: ignore */
memcpy(p + 1, buf, buflen); memcpy(p + 1, buf, buflen);
} }
p[0] = prefix; p[0] = prefix;
@@ -407,6 +410,7 @@ static int sm_encrypt(const struct sm_ctx *ctx, sc_card_t *card,
goto err; goto err;
} }
mac_data = p; mac_data = p;
/* Flawfinder: ignore */
memcpy(mac_data + mac_data_len, asn1, asn1_len); memcpy(mac_data + mac_data_len, asn1, asn1_len);
mac_data_len += asn1_len; mac_data_len += asn1_len;
r = add_padding(ctx, mac_data, mac_data_len, &mac_data); 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; r = SC_ERROR_OUT_OF_MEMORY;
goto err; goto err;
} }
/* Flawfinder: ignore */
memcpy((u8 *) sm_apdu->data, sm_data, sm_data_len); memcpy((u8 *) sm_apdu->data, sm_data, sm_data_len);
sm_apdu->datalen = sm_data_len; sm_apdu->datalen = sm_data_len;
sm_apdu->lc = sm_apdu->datalen; 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; r = SC_ERROR_OUT_OF_MEMORY;
goto err; goto err;
} }
/* Flawfinder: ignore */
memcpy(apdu->resp, data, r); memcpy(apdu->resp, data, r);
apdu->resplen = r; apdu->resplen = r;
} else { } else {