Don't cast second argument of mem_printf_hook (%b) to size_t.
authorTobias Brunner <tobias@strongswan.org>
Thu, 22 Mar 2012 15:13:15 +0000 (16:13 +0100)
committerTobias Brunner <tobias@strongswan.org>
Tue, 27 Mar 2012 07:10:34 +0000 (09:10 +0200)
Also treat the given number as unsigned int.

Due to the printf hook registration the second argument of
mem_printf_hook (if called via printf etc.) is always of type int*.
Casting this to a size_t pointer and then dereferencing that as int does
not work on big endian machines if int is smaller than size_t (e.g. on ppc64).

In order to make this change work if the argument is of a type larger
than int, size_t for instance, the second argument for %b has to be casted
to (u_)int.

src/libcharon/encoding/generator.c
src/libcharon/encoding/parser.c
src/libcharon/plugins/eap_sim_pcsc/eap_sim_pcsc_card.c
src/libcharon/plugins/smp/smp.c
src/libcharon/plugins/socket_dynamic/socket_dynamic_socket.c
src/libstrongswan/chunk.c
src/libstrongswan/plugins/fips_prf/fips_prf.c
src/libstrongswan/utils.c
src/libstrongswan/utils.h

index ce38443..60fa7e0 100644 (file)
@@ -523,7 +523,7 @@ METHOD(generator_t, generate_payload, void,
                 payload_type_names, payload_type);
        DBG3(DBG_ENC, "generated data for this payload %b",
                 this->buffer + offset_start,
-                this->out_position - this->buffer - offset_start);
+                (u_int)(this->out_position - this->buffer - offset_start));
 }
 
 METHOD(generator_t, destroy, void,
index 6309a5c..e492103 100644 (file)
@@ -377,7 +377,7 @@ METHOD(parser_t, parse_payload, status_t,
                 payload_type_names, payload_type, this->input_roof - this->byte_pos);
 
        DBG3(DBG_ENC, "parsing payload from %b",
-                this->byte_pos, this->input_roof - this->byte_pos);
+                this->byte_pos, (u_int)(this->input_roof - this->byte_pos));
 
        /* base pointer for output, avoids casting in every rule */
        output = pld;
index 6297924..c3f0f24 100644 (file)
@@ -207,7 +207,8 @@ METHOD(simaka_card_t, get_triplet, bool,
                if (dwRecvLength < APDU_STATUS_LEN ||
                        pbRecvBuffer[dwRecvLength-APDU_STATUS_LEN] != APDU_SW1_RESPONSE_DATA)
                {
-                       DBG1(DBG_IKE, "Select MF failed: %b", pbRecvBuffer, dwRecvLength);
+                       DBG1(DBG_IKE, "Select MF failed: %b", pbRecvBuffer,
+                                (u_int)dwRecvLength);
                        continue;
                }
 
@@ -223,7 +224,8 @@ METHOD(simaka_card_t, get_triplet, bool,
                if (dwRecvLength < APDU_STATUS_LEN ||
                        pbRecvBuffer[dwRecvLength-APDU_STATUS_LEN] != APDU_SW1_RESPONSE_DATA)
                {
-                       DBG1(DBG_IKE, "Select DF GSM failed: %b", pbRecvBuffer, dwRecvLength);
+                       DBG1(DBG_IKE, "Select DF GSM failed: %b", pbRecvBuffer,
+                                (u_int)dwRecvLength);
                        continue;
                }
 
@@ -239,7 +241,8 @@ METHOD(simaka_card_t, get_triplet, bool,
                if (dwRecvLength < APDU_STATUS_LEN ||
                        pbRecvBuffer[dwRecvLength-APDU_STATUS_LEN] != APDU_SW1_RESPONSE_DATA)
                {
-                       DBG1(DBG_IKE, "Select IMSI failed: %b", pbRecvBuffer, dwRecvLength);
+                       DBG1(DBG_IKE, "Select IMSI failed: %b", pbRecvBuffer,
+                                (u_int)dwRecvLength);
                        continue;
                }
 
@@ -255,14 +258,15 @@ METHOD(simaka_card_t, get_triplet, bool,
                if (dwRecvLength < APDU_STATUS_LEN ||
                        pbRecvBuffer[dwRecvLength-APDU_STATUS_LEN] != APDU_SW1_SUCCESS)
                {
-                       DBG1(DBG_IKE, "Select IMSI failed: %b", pbRecvBuffer, dwRecvLength);
+                       DBG1(DBG_IKE, "Select IMSI failed: %b", pbRecvBuffer,
+                                (u_int)dwRecvLength);
                        continue;
                }
 
                if (!decode_imsi_ef(pbRecvBuffer, dwRecvLength-APDU_STATUS_LEN, imsi))
                {
                        DBG1(DBG_IKE, "Couldn't decode IMSI EF: %b",
-                                pbRecvBuffer, dwRecvLength);
+                                pbRecvBuffer, (u_int)dwRecvLength);
                        continue;
                }
 
@@ -288,7 +292,7 @@ METHOD(simaka_card_t, get_triplet, bool,
                        pbRecvBuffer[dwRecvLength-APDU_STATUS_LEN] != APDU_SW1_RESPONSE_DATA)
                {
                        DBG1(DBG_IKE, "Run GSM Algorithm failed: %b",
-                                pbRecvBuffer, dwRecvLength);
+                                pbRecvBuffer, (u_int)dwRecvLength);
                        continue;
                }
 
@@ -305,7 +309,8 @@ METHOD(simaka_card_t, get_triplet, bool,
                if (dwRecvLength < APDU_STATUS_LEN ||
                        pbRecvBuffer[dwRecvLength-APDU_STATUS_LEN] != APDU_SW1_SUCCESS)
                {
-                       DBG1(DBG_IKE, "Get Response failed: %b", pbRecvBuffer, dwRecvLength);
+                       DBG1(DBG_IKE, "Get Response failed: %b", pbRecvBuffer,
+                                (u_int)dwRecvLength);
                        continue;
                }
 
@@ -320,7 +325,7 @@ METHOD(simaka_card_t, get_triplet, bool,
                else
                {
                        DBG1(DBG_IKE, "Get Response incorrect length: %b",
-                                pbRecvBuffer, dwRecvLength);
+                                pbRecvBuffer, (u_int)dwRecvLength);
                        continue;
                }
 
index 830ed4c..1873d96 100644 (file)
@@ -642,7 +642,7 @@ static job_requeue_t process(int *fdp)
                DBG2(DBG_CFG, "SMP XML connection closed");
                return JOB_REQUEUE_NONE;
        }
-       DBG3(DBG_CFG, "got XML request: %b", buffer, len);
+       DBG3(DBG_CFG, "got XML request: %b", buffer, (u_int)len);
 
        reader = xmlReaderForMemory(buffer, len, NULL, NULL, 0);
        if (reader == NULL)
index 74dba82..eee3814 100644 (file)
@@ -235,7 +235,7 @@ static packet_t *receive_packet(private_socket_dynamic_socket_t *this,
                DBG1(DBG_NET, "receive buffer too small, packet discarded");
                return NULL;
        }
-       DBG3(DBG_NET, "received packet %b", buffer, len);
+       DBG3(DBG_NET, "received packet %b", buffer, (u_int)len);
 
        if (len < MARKER_LEN)
        {
index bb87900..9397c4e 100644 (file)
@@ -668,7 +668,8 @@ int chunk_printf_hook(char *dst, size_t len, printf_hook_spec_t *spec,
 
        if (!spec->hash)
        {
-               const void *new_args[] = {&chunk->ptr, &chunk->len};
+               u_int chunk_len = chunk->len;
+               const void *new_args[] = {&chunk->ptr, &chunk_len};
                return mem_printf_hook(dst, len, spec, new_args);
        }
 
index ee71f6e..c066636 100644 (file)
@@ -127,14 +127,14 @@ METHOD(prf_t, get_bytes, void,
        {
                /* a. XVAL = (XKEY + XSEED j) mod 2^b */
                add_mod(this->b, xkey, xseed, xval);
-               DBG3(DBG_LIB, "XVAL %b", xval, this->b);
+               DBG3(DBG_LIB, "XVAL %b", xval, (u_int)this->b);
                /* b. wi = G(t, XVAL ) */
                this->g(this, chunk_create(xval, this->b), &w[i * this->b]);
-               DBG3(DBG_LIB, "w[%d] %b", i, &w[i * this->b], this->b);
+               DBG3(DBG_LIB, "w[%d] %b", i, &w[i * this->b], (u_int)this->b);
                /* c. XKEY = (1 + XKEY + wi) mod 2b */
                add_mod(this->b, xkey, &w[i * this->b], sum);
                add_mod(this->b, sum, one, xkey);
-               DBG3(DBG_LIB, "XKEY %b", xkey, this->b);
+               DBG3(DBG_LIB, "XKEY %b", xkey, (u_int)this->b);
        }
 
        /* 3.3 done already, mod q not used */
index 5a104de..f76245a 100644 (file)
@@ -444,7 +444,7 @@ int mem_printf_hook(char *dst, size_t dstlen,
                                        printf_hook_spec_t *spec, const void *const *args)
 {
        char *bytes = *((void**)(args[0]));
-       int len = *((size_t*)(args[1]));
+       u_int len = *((int*)(args[1]));
 
        char buffer[BYTES_PER_LINE * 3];
        char ascii_buffer[BYTES_PER_LINE + 1];
@@ -455,7 +455,7 @@ int mem_printf_hook(char *dst, size_t dstlen,
        int i = 0;
        int written = 0;
 
-       written += print_in_hook(dst, dstlen, "=> %d bytes @ %p", len, bytes);
+       written += print_in_hook(dst, dstlen, "=> %u bytes @ %p", len, bytes);
 
        while (bytes_pos < bytes_roof)
        {
index 3ddaea0..cedfe8f 100644 (file)
@@ -637,7 +637,7 @@ int time_delta_printf_hook(char *dst, size_t len, printf_hook_spec_t *spec,
  * printf hook for memory areas.
  *
  * Arguments are:
- *     u_char *ptr, int len
+ *     u_char *ptr, u_int len
  */
 int mem_printf_hook(char *dst, size_t len, printf_hook_spec_t *spec,
                                        const void *const *args);