Committer: Mircea Gherzan <mircea.gherzan@xxxxxxxxxxxxxx> Date: 17/05/2010 at 19:58:50 Revision: 4545 Revision-id: mircea.gherzan@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Branch nick: trunk Log: Add the warning flag for pointer arithmetic. Quite a lot of code had to be fixed for this one. Modified: M configure.ac M firewall/conntrack.c M firewall/pisa.c M hipd/blind.c M hipd/close.c M hipd/input.c M hipd/keymat.c M hipd/registration.c M hipd/update.c M lib/core/builder.c M lib/core/crypto.c M lib/core/crypto.h M lib/core/hit.c M lib/core/protodefs.h M lib/tool/nlink.c === modified file 'configure.ac' --- configure.ac 2010-05-16 17:58:14 +0000 +++ configure.ac 2010-05-17 16:55:10 +0000 @@ -66,7 +66,7 @@ # Set default AM_CFLAGS for the complete project. -AC_SUBST(AM_CFLAGS, "-std=c99 -Werror -Wall -Wredundant-decls -Wdisabled-optimization -Wundef -Wstrict-prototypes -Wmissing-prototypes -Wno-deprecated-declarations -fno-strict-aliasing") +AC_SUBST(AM_CFLAGS, "-std=c99 -Werror -Wall -Wredundant-decls -Wdisabled-optimization -Wundef -Wstrict-prototypes -Wmissing-prototypes -Wno-deprecated-declarations -Wpointer-arith -fno-strict-aliasing") # Set the preprocessor flags for the entire project AC_SUBST(AM_CPPFLAGS, "-D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=500") === modified file 'firewall/conntrack.c' --- firewall/conntrack.c 2010-05-16 21:02:09 +0000 +++ firewall/conntrack.c 2010-05-17 16:55:10 +0000 @@ -639,7 +639,8 @@ sizeof(struct hip_locator_info_addr_item); HIP_DEBUG("esp_tuple_from_esp_info_locator: %d addresses in locator\n", n); if (n > 0) { - locator_addr = (void *) locator + sizeof(struct hip_locator); + locator_addr = (struct hip_locator_info_addr_item *) + ((uint8_t *) locator + sizeof(struct hip_locator)); while (n > 0) { struct esp_address *esp_address = malloc(sizeof(struct esp_address)); memcpy(&esp_address->dst_addr, @@ -1195,7 +1196,8 @@ goto out_err; } - locator_addr = (void *) locator + sizeof(struct hip_locator); + locator_addr = (struct hip_locator_info_addr_item *) + ((uint8_t *) locator + sizeof(struct hip_locator)); while (n > 0) { esp_tuple->dst_addr_list = update_esp_address(esp_tuple->dst_addr_list, @@ -1235,7 +1237,8 @@ / sizeof(struct hip_locator_info_addr_item); HIP_DEBUG(" %d locator addresses\n", n); - locator_addr = (void *) locator + sizeof(struct hip_locator); + locator_addr = (struct hip_locator_info_addr_item *) + ((uint8_t *) locator + sizeof(struct hip_locator)); _HIP_DEBUG("locator addr: old tuple"); print_esp_tuple(esp_tuple); === modified file 'firewall/pisa.c' --- firewall/pisa.c 2010-05-08 18:45:51 +0000 +++ firewall/pisa.c 2010-05-17 16:55:10 +0000 @@ -140,7 +140,7 @@ memcpy(key + 32, &pisa_random_data[rnd][0], PISA_RANDOM_LEN); HMAC(EVP_sha1(), key, 32 + PISA_RANDOM_LEN, data, data_len, - data + data_len, &len); + (uint8_t *) data + data_len, &len); out_err: return err; === modified file 'hipd/blind.c' --- hipd/blind.c 2010-04-16 18:50:27 +0000 +++ hipd/blind.c 2010-05-17 16:55:10 +0000 @@ -425,9 +425,10 @@ */ int hip_blind_build_r2(struct hip_common *i2, struct hip_common *r2, hip_ha_t *entry, uint16_t *mask) { - int err = 0, host_id_in_enc_len = 0; - char *enc_in_msg = NULL, *host_id_in_enc = NULL; - unsigned char *iv = NULL; + int err = 0, host_id_in_enc_len = 0; + uint8_t *enc_in_msg = NULL; + uint8_t *host_id_in_enc = NULL; + unsigned char *iv = NULL; /************ Encrypted ***********/ switch (entry->hip_transform) { @@ -438,8 +439,7 @@ HIP_ASSERT(enc_in_msg); /* Builder internal error. */ iv = ((struct hip_encrypted_aes_sha1 *) enc_in_msg)->iv; get_random_bytes(iv, 16); - host_id_in_enc = enc_in_msg + - sizeof(struct hip_encrypted_aes_sha1); + host_id_in_enc = enc_in_msg + sizeof(struct hip_encrypted_aes_sha1); break; case HIP_HIP_3DES_SHA1: HIP_IFEL(hip_build_param_encrypted_3des_sha1(r2, (struct hip_tlv_common *) entry->our_pub), @@ -448,8 +448,7 @@ HIP_ASSERT(enc_in_msg); /* Builder internal error. */ iv = ((struct hip_encrypted_3des_sha1 *) enc_in_msg)->iv; get_random_bytes(iv, 8); - host_id_in_enc = enc_in_msg + - sizeof(struct hip_encrypted_3des_sha1); + host_id_in_enc = enc_in_msg + sizeof(struct hip_encrypted_3des_sha1); break; case HIP_HIP_NULL_SHA1: HIP_IFEL(hip_build_param_encrypted_null_sha1(r2, (struct hip_tlv_common *) entry->our_pub), @@ -457,8 +456,7 @@ enc_in_msg = hip_get_param(r2, HIP_PARAM_ENCRYPTED); HIP_ASSERT(enc_in_msg); /* Builder internal error. */ iv = NULL; - host_id_in_enc = enc_in_msg + - sizeof(struct hip_encrypted_null_sha1); + host_id_in_enc = enc_in_msg + sizeof(struct hip_encrypted_null_sha1); break; default: HIP_IFEL(1, -ENOSYS, "HIP transform not supported (%d)\n", @@ -483,7 +481,7 @@ HIP_IFEL(hip_crypto_encrypted(host_id_in_enc, iv, entry->hip_transform, host_id_in_enc_len, - &entry->hip_enc_out.key, + entry->hip_enc_out.key, HIP_DIRECTION_ENCRYPT), -1, "Building of param encrypted failed\n"); @@ -553,7 +551,7 @@ } HIP_IFEL(hip_crypto_encrypted(host_id_in_enc, iv, entry->hip_transform, - crypto_len, &entry->hip_enc_in.key, + crypto_len, entry->hip_enc_in.key, HIP_DIRECTION_DECRYPT), -EINVAL, "Decryption of Host ID failed\n"); === modified file 'hipd/close.c' --- hipd/close.c 2010-04-16 18:50:27 +0000 +++ hipd/close.c 2010-05-17 16:55:10 +0000 @@ -33,7 +33,7 @@ #endif int err = 0, mask = 0; hip_hit_t *peer = (hip_hit_t *) opaque; - int delete_ha_info = *(int *) (opaque + sizeof(hip_hit_t)); + int delete_ha_info = *(int *) ((uint8_t *)opaque + sizeof(hip_hit_t)); struct hip_common *close = NULL; === modified file 'hipd/input.c' --- hipd/input.c 2010-05-16 21:02:09 +0000 +++ hipd/input.c 2010-05-17 16:55:10 +0000 @@ -1122,7 +1122,7 @@ HIP_IFEL(hip_crypto_encrypted(host_id_in_enc, iv, transform_hip_suite, host_id_in_enc_len, - &ctx->hip_enc_out.key, + ctx->hip_enc_out.key, HIP_DIRECTION_ENCRYPT), -1, "Building of param encrypted failed\n"); @@ -2050,8 +2050,8 @@ * Note, that the original packet has the data still encrypted. */ if (!host_id_found) { HIP_IFEL(hip_crypto_encrypted(host_id_in_enc, iv, hip_tfm, crypto_len, - (is_loopback ? &i2_context.hip_enc_out.key : - &i2_context.hip_enc_in.key), + (is_loopback ? i2_context.hip_enc_out.key : + i2_context.hip_enc_in.key), HIP_DIRECTION_DECRYPT), -EKEYREJECTED, "Failed to decrypt the HOST_ID parameter. Dropping the I2 " \ === modified file 'hipd/keymat.c' --- hipd/keymat.c 2010-04-16 18:41:45 +0000 +++ hipd/keymat.c 2010-05-17 16:55:10 +0000 @@ -167,8 +167,8 @@ while (dstoffset < dstbuflen) { hip_build_digest(HIP_DIGEST_SHA1, shabuffer, kij_len + HIP_AH_SHA_LEN + 1, - dstbuf + dstoffset); - seedkey = dstbuf + dstoffset; + (uint8_t *) dstbuf + dstoffset); + seedkey = (uint8_t *) dstbuf + dstoffset; dstoffset += HIP_AH_SHA_LEN; index_nbr++; hip_update_keymat_buffer(shabuffer, seedkey, HIP_AH_SHA_LEN, @@ -212,7 +212,7 @@ goto out_err; } - ret = keymat->keymatdst + keymat->offset; + ret = (uint8_t *) keymat->keymatdst + keymat->offset; keymat->offset += length; === modified file 'hipd/registration.c' --- hipd/registration.c 2010-04-16 18:50:02 +0000 +++ hipd/registration.c 2010-05-17 16:55:10 +0000 @@ -690,7 +690,7 @@ /* Allocate memory for types */ /* Get a pointer to the actual registration types. */ - reg_types = hip_get_param_contents_direct(reg_request) + + reg_types = (uint8_t *) hip_get_param_contents_direct(reg_request) + sizeof(reg_request->lifetime); HIP_DEBUG("REG_REQUEST parameter found. Requested lifetime: 0x%x, " \ @@ -826,7 +826,7 @@ type_count = hip_get_param_contents_len(reg_response) - sizeof(reg_response->lifetime); - reg_types = hip_get_param_contents_direct(reg_response) + + reg_types = (uint8_t *) hip_get_param_contents_direct(reg_response) + sizeof(reg_response->lifetime); if (reg_response->lifetime == 0) { @@ -873,7 +873,7 @@ while (hip_get_param_type(reg_failed) == HIP_PARAM_REG_FAILED) { type_count = hip_get_param_contents_len(reg_failed) - sizeof(reg_failed->failure_type); - reg_types = hip_get_param_contents_direct(reg_failed) + + reg_types = (uint8_t *) hip_get_param_contents_direct(reg_failed) + sizeof(reg_failed->failure_type); hip_get_registration_failure_string(reg_failed->failure_type, reason); === modified file 'hipd/update.c' --- hipd/update.c 2010-04-20 12:15:57 +0000 +++ hipd/update.c 2010-05-17 16:55:10 +0000 @@ -214,11 +214,10 @@ HIP_DEBUG("echo opaque data len=%d\n", hip_get_param_contents_len(echo_request)); HIP_HEXDUMP("ECHO_REQUEST ", - (void *) echo_request + - sizeof(struct hip_tlv_common), + (uint8_t *) echo_request + sizeof(struct hip_tlv_common), hip_get_param_contents_len(echo_request)); - HIP_IFEL(hip_build_param_echo(update_packet_to_send, (void *) echo_request + - sizeof(struct hip_tlv_common), + HIP_IFEL(hip_build_param_echo(update_packet_to_send, + (uint8_t *) echo_request + sizeof(struct hip_tlv_common), hip_get_param_contents_len(echo_request), 1, 0), -1, "Building of ECHO_RESPONSE failed\n"); } === modified file 'lib/core/builder.c' --- lib/core/builder.c 2010-05-16 21:02:09 +0000 +++ lib/core/builder.c 2010-05-17 16:55:10 +0000 @@ -771,15 +771,16 @@ const struct hip_tlv_common *param) { int ok = 0; + /* length in bytes */ int param_len = hip_get_param_total_len(param); - void *pos = (void *) param; + uint8_t *pos = (uint8_t *) param; /* Note: the lower limit is not checked, because there really is no * lower limit. */ - if (pos == ((void *) msg)) { + if (pos == ((uint8_t *) msg)) { HIP_ERROR("not a parameter\n"); - } else if (pos + param_len > ((void *) msg) + HIP_MAX_PACKET) { + } else if (pos + param_len > ((uint8_t *) msg) + HIP_MAX_PACKET) { HIP_DEBUG("param far too long (%d)\n", param_len); } else if (param_len > hip_get_msg_total_len(msg)) { HIP_DEBUG("param too long (%d) msg_len %d\n", param_len, @@ -805,7 +806,7 @@ const struct hip_tlv_common *current_param) { struct hip_tlv_common *next_param = NULL; - void *pos = (void *) current_param; + uint8_t *pos = (uint8_t *) current_param; if (!msg) { HIP_ERROR("msg null\n"); @@ -813,10 +814,10 @@ } if (current_param == NULL) { - pos = (void *) msg; + pos = (uint8_t *) msg; } - if (pos == msg) { + if (pos == (void *) msg) { pos += sizeof(struct hip_common); } else { pos += hip_get_param_total_len(current_param); @@ -895,7 +896,7 @@ void *hip_get_param_contents(const struct hip_common *msg, hip_tlv_type_t param_type) { - void *contents = hip_get_param(msg, param_type); + uint8_t *contents = hip_get_param(msg, param_type); if (contents) { contents += sizeof(struct hip_tlv_common); } @@ -911,7 +912,7 @@ */ void *hip_get_param_contents_direct(const void *tlv_common) { - return ((void *) tlv_common) + sizeof(struct hip_tlv_common); + return ((uint8_t *) tlv_common) + sizeof(struct hip_tlv_common); } /** @@ -934,7 +935,7 @@ struct hip_tlv_common *current_param = NULL; struct hip_tlv_common *last_used_pos = NULL; void *free_pos = NULL; - void *first_pos = ((void *) msg) + sizeof(struct hip_common); + uint8_t *first_pos = ((uint8_t *) msg) + sizeof(struct hip_common); /* Check for no parameters: this has to be checked separately because * we cannot tell from the return value of get_next_param() whether @@ -960,7 +961,7 @@ if (last_used_pos == NULL) { free_pos = NULL; /* the message was full */ } else { - free_pos = ((void *) last_used_pos) + + free_pos = ((uint8_t *) last_used_pos) + hip_get_param_total_len(last_used_pos); } @@ -980,7 +981,7 @@ void hip_calc_hdr_len(struct hip_common *msg) { struct hip_tlv_common *param = NULL; - void *pos = (void *) msg; + uint8_t *pos = (uint8_t *) msg; /* We cannot call get_next() or get_free() because they need a valid * header length which is to be (possibly) calculated now. So, the @@ -1071,7 +1072,7 @@ void hip_dump_msg(const struct hip_common *msg) { struct hip_tlv_common *current_param = NULL; - void *contents = NULL; + uint8_t *contents = NULL; /* The value of the "Length"-field in current parameter. */ hip_tlv_len_t len = 0; /* Total length of the parameter (type+length+value+padding), and the @@ -1489,9 +1490,10 @@ const void *contents) { const struct hip_tlv_common *param = (struct hip_tlv_common *) parameter_hdr; - void *src = NULL, *dst = NULL; + void *src = NULL; + uint8_t *dst = NULL; int err = 0, size = 0; - void *max_dst = ((void *) msg) + HIP_MAX_PACKET; + uint8_t *max_dst = ((uint8_t *) msg) + HIP_MAX_PACKET; _HIP_DEBUG("\n"); @@ -1626,7 +1628,7 @@ int hip_build_param(struct hip_common *msg, const void *tlv_common) { int err = 0; - void *contents = ((void *) tlv_common) + sizeof(struct hip_tlv_common); + uint8_t *contents = ((uint8_t *) tlv_common) + sizeof(struct hip_tlv_common); if (tlv_common == NULL) { err = -EFAULT; @@ -2863,12 +2865,13 @@ if (type == HIP_PARAM_HIP_TRANSFORM) { table = supported_hip_tf; table_n = sizeof(supported_hip_tf) / sizeof(uint16_t); - tfm = (void *) transform_tlv + sizeof(struct hip_tlv_common); + tfm = (uint16_t*) ((uint8_t *) transform_tlv + sizeof(struct hip_tlv_common)); pkt_tfms = hip_get_param_contents_len(transform_tlv) / sizeof(uint16_t); } else if (type == HIP_PARAM_ESP_TRANSFORM) { table = supported_esp_tf; table_n = sizeof(supported_esp_tf) / sizeof(uint16_t); - tfm = (void *) transform_tlv + sizeof(struct hip_tlv_common) + sizeof(uint16_t); + tfm = (uint16_t*) ((uint8_t *) transform_tlv + + sizeof(struct hip_tlv_common) + sizeof(uint16_t)); pkt_tfms = (hip_get_param_contents_len(transform_tlv) - sizeof(uint16_t)) / sizeof(uint16_t); } else { HIP_ERROR("Invalid type %u\n", type); === modified file 'lib/core/crypto.c' --- lib/core/crypto.c 2010-04-09 17:56:34 +0000 +++ lib/core/crypto.c 2010-05-17 16:55:10 +0000 @@ -357,7 +357,7 @@ * otherwise. */ int hip_crypto_encrypted(void *data, const void *iv_orig, int alg, int len, - void *key, int direction) + uint8_t *key, int direction) { void *result = NULL; int err = -1; === modified file 'lib/core/crypto.h' --- lib/core/crypto.h 2010-04-22 10:12:54 +0000 +++ lib/core/crypto.h 2010-05-17 16:55:10 +0000 @@ -106,7 +106,7 @@ int impl_dsa_verify(uint8_t *digest, DSA *dsa, uint8_t *signature); int hip_write_hmac(int type, const void *key, void *in, int in_len, void *out); int hip_crypto_encrypted(void *data, const void *iv, int enc_alg, int enc_len, - void *enc_key, int direction); + uint8_t *enc_key, int direction); void get_random_bytes(void *buf, int n); #endif /* HIP_LIB_CORE_CRYPTO_H */ === modified file 'lib/core/hit.c' --- lib/core/hit.c 2010-04-09 16:24:44 +0000 +++ lib/core/hit.c 2010-05-17 16:55:10 +0000 @@ -79,7 +79,7 @@ { uint8_t hash[HIP_AH_SHA_LEN]; - hip_build_digest(HIP_DIGEST_SHA1, ptr + sizeof(uint16_t), + hip_build_digest(HIP_DIGEST_SHA1, (uint8_t *)ptr + sizeof(uint16_t), 7 * sizeof(uint16_t), hash); return *((unsigned long *) hash); === modified file 'lib/core/protodefs.h' --- lib/core/protodefs.h 2010-05-16 21:02:09 +0000 +++ lib/core/protodefs.h 2010-05-17 16:55:10 +0000 @@ -571,7 +571,7 @@ typedef struct hip_tlv_common hip_tlv_common_t; struct hip_crypto_key { - unsigned char key[HIP_MAX_KEY_LEN]; + uint8_t key[HIP_MAX_KEY_LEN]; }; typedef struct hip_crypto_key hip_crypto_key_t; === modified file 'lib/tool/nlink.c' --- lib/tool/nlink.c 2010-05-17 12:41:25 +0000 +++ lib/tool/nlink.c 2010-05-17 16:55:10 +0000 @@ -43,7 +43,7 @@ #define PREFIXLEN_SPECIFIED 1 #define NLMSG_TAIL(nmsg) \ - ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len))) + ((struct rtattr *) (((uint8_t *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len))) typedef int (*rtnl_filter_t)(const struct sockaddr_nl *, const struct nlmsghdr *n, void **);