unified usage of sizeof. found some potential memory corruptions with that.
git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@341 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
@@ -53,8 +53,8 @@ void print_usage(const char *app_name, const struct option options[],
|
||||
arg_str = "";
|
||||
break;
|
||||
}
|
||||
snprintf(buf, sizeof(buf), "--%-13s%s%s", options[i].name, tmp, arg_str);
|
||||
if (strnlen(buf, sizeof(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';
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ detect_card_presence(int slot)
|
||||
{
|
||||
int sc_result;
|
||||
|
||||
if (slot >= sizeof *card_in_slot)
|
||||
if (slot >= sizeof card_in_slot/sizeof *card_in_slot )
|
||||
return SC_ERROR_INVALID_ARGUMENTS;
|
||||
|
||||
sc_result = sc_detect_card_presence(reader, slot);
|
||||
@@ -137,7 +137,7 @@ int ccid_initialize(int reader_id, const char *cdriver, int verbose)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sizeof(card_in_slot)/sizeof(*card_in_slot); i++)
|
||||
for (i = 0; i < sizeof card_in_slot/sizeof *card_in_slot; i++)
|
||||
card_in_slot[i] = NULL;
|
||||
|
||||
i = initialize(reader_id, cdriver, verbose, &ctx, &reader);
|
||||
@@ -161,7 +161,7 @@ int ccid_initialize(int reader_id, const char *cdriver, int verbose)
|
||||
void ccid_shutdown()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < sizeof *card_in_slot; i++) {
|
||||
for (i = 0; i < sizeof card_in_slot/sizeof *card_in_slot; i++) {
|
||||
if (card_in_slot[i] && sc_card_valid(card_in_slot[i])) {
|
||||
sc_disconnect_card(card_in_slot[i], 0);
|
||||
}
|
||||
@@ -184,7 +184,7 @@ static int get_rapdu(sc_apdu_t *apdu, size_t slot, __u8 **buf, size_t *resplen)
|
||||
{
|
||||
int sc_result;
|
||||
|
||||
if (!apdu || !buf || !resplen || slot >= sizeof *card_in_slot) {
|
||||
if (!apdu || !buf || !resplen || slot >= sizeof card_in_slot/sizeof *card_in_slot) {
|
||||
sc_result = SC_ERROR_INVALID_ARGUMENTS;
|
||||
goto err;
|
||||
}
|
||||
@@ -410,7 +410,7 @@ perform_PC_to_RDR_IccPowerOn(const __u8 *in, size_t inlen, __u8 **out, size_t *o
|
||||
request->abRFU != 0)
|
||||
sc_debug(ctx, "warning: malformed PC_to_RDR_IccPowerOn");
|
||||
|
||||
if (request->bSlot < sizeof *card_in_slot) {
|
||||
if (request->bSlot < sizeof card_in_slot/sizeof *card_in_slot) {
|
||||
if (card_in_slot[request->bSlot]
|
||||
&& sc_card_valid(card_in_slot[request->bSlot])) {
|
||||
sc_debug(ctx, "Card is already powered on.");
|
||||
@@ -465,7 +465,7 @@ perform_PC_to_RDR_IccPowerOff(const __u8 *in, size_t inlen, __u8 **out, size_t *
|
||||
request->abRFU2 != 0)
|
||||
sc_debug(ctx, "warning: malformed PC_to_RDR_IccPowerOff");
|
||||
|
||||
if (request->bSlot > sizeof *card_in_slot)
|
||||
if (request->bSlot > sizeof card_in_slot/sizeof *card_in_slot)
|
||||
sc_result = SC_ERROR_INVALID_DATA;
|
||||
else {
|
||||
sc_reset(card_in_slot[request->bSlot]);
|
||||
@@ -496,7 +496,7 @@ perform_PC_to_RDR_XfrBlock(const u8 *in, size_t inlen, __u8** out, size_t *outle
|
||||
request->bBWI != 0)
|
||||
sc_debug(ctx, "malformed PC_to_RDR_XfrBlock, will continue anyway");
|
||||
|
||||
if (request->bSlot > sizeof *card_in_slot)
|
||||
if (request->bSlot > sizeof card_in_slot/sizeof *card_in_slot)
|
||||
sc_result = SC_ERROR_INVALID_DATA;
|
||||
else {
|
||||
sc_result = build_apdu(ctx, abDataIn, __le32_to_cpu(request->dwLength),
|
||||
@@ -536,7 +536,7 @@ perform_PC_to_RDR_GetParamters(const __u8 *in, size_t inlen, __u8** out, size_t
|
||||
request->dwLength != __constant_cpu_to_le32(0))
|
||||
sc_debug(ctx, "warning: malformed PC_to_RDR_GetParamters");
|
||||
|
||||
if (request->bSlot < sizeof *card_in_slot) {
|
||||
if (request->bSlot < sizeof card_in_slot/sizeof *card_in_slot) {
|
||||
switch (reader->slot[request->bSlot].active_protocol) {
|
||||
case SC_PROTO_T0:
|
||||
result = realloc(*out, sizeof *result + sizeof *t0);
|
||||
@@ -793,8 +793,8 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card,
|
||||
__le32 dword;
|
||||
__u8 *p;
|
||||
|
||||
memset(&pace_input, 0, sizeof(pace_input));
|
||||
memset(&pace_output, 0, sizeof(pace_output));
|
||||
memset(&pace_input, 0, sizeof pace_input);
|
||||
memset(&pace_output, 0, sizeof pace_output);
|
||||
|
||||
|
||||
if (!abDataOut || !abDataOutLen) {
|
||||
@@ -848,7 +848,7 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card,
|
||||
parsed += pace_input.pin_length;
|
||||
|
||||
|
||||
if (abDatalen < parsed+sizeof(word)) {
|
||||
if (abDatalen < parsed+sizeof word) {
|
||||
sc_error(ctx, "Buffer too small, could not get lengthCertificateDescription");
|
||||
sc_result = SC_ERROR_INVALID_ARGUMENTS;
|
||||
goto err;
|
||||
@@ -1091,7 +1091,7 @@ perform_PC_to_RDR_Secure(const __u8 *in, size_t inlen, __u8** out, size_t *outle
|
||||
if (request->bMessageType != 0x69)
|
||||
sc_debug(ctx, "warning: malformed PC_to_RDR_Secure");
|
||||
|
||||
if (request->bSlot > sizeof *card_in_slot) {
|
||||
if (request->bSlot > sizeof card_in_slot/sizeof *card_in_slot) {
|
||||
sc_error(ctx, "Received request to invalid slot (bSlot=0x%02x)", request->bSlot);
|
||||
goto err;
|
||||
}
|
||||
@@ -1144,8 +1144,8 @@ perform_PC_to_RDR_Secure(const __u8 *in, size_t inlen, __u8** out, size_t *outle
|
||||
bmPINBlockString = modify->bmPINBlockString;
|
||||
bmFormatString = modify->bmFormatString;
|
||||
bNumberMessage = modify->bNumberMessage;
|
||||
abPINApdu = (__u8*) modify + sizeof(*modify);
|
||||
apdulen = __le32_to_cpu(request->dwLength) - sizeof(*modify) - sizeof(__u8);
|
||||
abPINApdu = (__u8*) modify + sizeof *modify;
|
||||
apdulen = __le32_to_cpu(request->dwLength) - sizeof *modify - sizeof(__u8);
|
||||
break;
|
||||
case 0x10:
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ int pace_translate_apdus(struct sm_ctx *sctx, sc_card_t *card)
|
||||
ssize_t linelen;
|
||||
int r;
|
||||
|
||||
memset(&apdu, 0, sizeof(apdu));
|
||||
memset(&apdu, 0, sizeof apdu);
|
||||
|
||||
while (1) {
|
||||
printf("Enter unencrypted APDU (empty line to exit)\n");
|
||||
@@ -148,7 +148,7 @@ int pace_translate_apdus(struct sm_ctx *sctx, sc_card_t *card)
|
||||
}
|
||||
|
||||
apdu.resp = buf;
|
||||
apdu.resplen = sizeof(buf);
|
||||
apdu.resplen = sizeof buf;
|
||||
|
||||
r = sm_transmit_apdu(sctx, card, &apdu);
|
||||
if (r < 0) {
|
||||
@@ -177,10 +177,10 @@ main (int argc, char **argv)
|
||||
time_t t_start, t_end;
|
||||
size_t outlen;
|
||||
|
||||
memset(&sctx, 0, sizeof(sctx));
|
||||
memset(&tmpctx, 0, sizeof(tmpctx));
|
||||
memset(&pace_input, 0, sizeof(pace_input));
|
||||
memset(&pace_output, 0, sizeof(pace_output));
|
||||
memset(&sctx, 0, sizeof sctx);
|
||||
memset(&tmpctx, 0, sizeof tmpctx);
|
||||
memset(&pace_input, 0, sizeof pace_input);
|
||||
memset(&pace_output, 0, sizeof pace_output);
|
||||
|
||||
while (1) {
|
||||
i = getopt_long(argc, argv, "hr:i::u::a::z::bC:D:N::RUtvoc:", options, &oindex);
|
||||
|
||||
@@ -89,7 +89,7 @@ int build_apdu(sc_context_t *ctx, const u8 *buf, size_t len, sc_apdu_t *apdu)
|
||||
return SC_ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
memset(apdu, 0, sizeof(*apdu));
|
||||
memset(apdu, 0, sizeof *apdu);
|
||||
p = buf;
|
||||
apdu->cla = *p++;
|
||||
apdu->ins = *p++;
|
||||
|
||||
@@ -604,7 +604,7 @@ static int autoconfig ()
|
||||
source_sink_intf.bNumEndpoints = 2;
|
||||
int i;
|
||||
if (!doiintf) {
|
||||
for (i=0; i<sizeof(stringtab)/sizeof(struct usb_string); i++) {
|
||||
for (i=0; i<sizeof stringtab/sizeof(struct usb_string); i++) {
|
||||
if (stringtab[i].id == STRINGID_INTERFACE) {
|
||||
stringtab[i].s = interrupt_off_string;
|
||||
break;
|
||||
@@ -1820,7 +1820,7 @@ main (int argc, char **argv)
|
||||
}
|
||||
|
||||
if (doserial) {
|
||||
for (i=0; i<sizeof(stringtab)/sizeof(struct usb_string); i++) {
|
||||
for (i=0; i<sizeof stringtab/sizeof(struct usb_string); i++) {
|
||||
if (stringtab[i].id == STRINGID_SERIAL) {
|
||||
stringtab[i].s = doserial;
|
||||
break;
|
||||
@@ -1840,7 +1840,7 @@ main (int argc, char **argv)
|
||||
fprintf (stderr, "serial=\"%s\"\n", doserial ? doserial : serial);
|
||||
|
||||
if (doiintf) {
|
||||
for (i=0; i<sizeof(stringtab)/sizeof(struct usb_string); i++) {
|
||||
for (i=0; i<sizeof stringtab/sizeof(struct usb_string); i++) {
|
||||
if (stringtab[i].id == STRINGID_INTERFACE) {
|
||||
stringtab[i].s = doiintf;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user