[hipl-dev] [Branch ~hipl-core/hipl/trunk] Rev 5965: Fix bug #789327:

  • From: noreply@xxxxxxxxxxxxx
  • To: HIPL core team <hipl-dev@xxxxxxxxxxxxx>
  • Date: Sat, 11 Jun 2011 18:49:13 -0000

Merge authors:
  Stefan Götz (stefan.goetz)
------------------------------------------------------------
revno: 5965 [merge]
fixes bug(s): https://launchpad.net/bugs/789327
committer: Stefan Götz <stefan.goetz@xxxxxx>
branch nick: hipl
timestamp: Sat 2011-06-11 20:46:09 +0200
message:
  Fix bug #789327:
  Add missing initialization to 'peer_addr' variable. Revision 5938 erroneously
    removed code that was necessary to change the value of the peer_addr pointer
    to an actual peer address. This caused a NULL pointer access and 
segmentation
    fault when handling a locator parameter during an UPDATE message.
  This merges the branch lp:~stefan.goetz/hipl/mobility-bug
modified:
  lib/core/prefix.c
  lib/core/prefix.h
  modules/update/hipd/update_param_handling.c


--
lp:hipl
https://code.launchpad.net/~hipl-core/hipl/trunk

Your team HIPL core team is subscribed to branch lp:hipl.
To unsubscribe from this branch go to 
https://code.launchpad.net/~hipl-core/hipl/trunk/+edit-subscription
=== modified file 'lib/core/prefix.c'
--- lib/core/prefix.c   2011-04-29 10:18:06 +0000
+++ lib/core/prefix.c   2011-06-08 18:32:15 +0000
@@ -58,8 +58,9 @@
  * @param hit the address to be tested
  * @return 1 if the address has the HIT prefix or zero otherwise
  */
-int ipv6_addr_is_hit(const struct in6_addr *hit)
+int ipv6_addr_is_hit(const struct in6_addr *const hit)
 {
+    HIP_ASSERT(hit);
     hip_closest_prefix_type hit_begin;
     memcpy(&hit_begin, hit, sizeof(hip_closest_prefix_type));
     hit_begin  = ntohl(hit_begin);
@@ -73,8 +74,9 @@
  * @param teredo the IPv6 address to be tested for Teredo prefix
  * @return 1 if the address has the Teredo prefix or zero otherwise
  */
-int ipv6_addr_is_teredo(const struct in6_addr *teredo)
+int ipv6_addr_is_teredo(const struct in6_addr *const teredo)
 {
+    HIP_ASSERT(teredo);
     hip_closest_prefix_type teredo_begin;
     memcpy(&teredo_begin, teredo, sizeof(hip_closest_prefix_type));
     teredo_begin  = ntohl(teredo_begin);
@@ -88,8 +90,9 @@
  * @param ip the IPv6 address to test
  * @return one if the address is all zeroes and zero otherwise
  */
-int ipv6_addr_is_null(const struct in6_addr *ip)
+int ipv6_addr_is_null(const struct in6_addr *const ip)
 {
+    HIP_ASSERT(ip);
     return (ip->s6_addr32[0] | ip->s6_addr32[1] |
             ip->s6_addr32[2] | ip->s6_addr32[3]) == 0;
 }
@@ -102,8 +105,9 @@
  * @return one if the IPv6 address was a real HIT and
  * '          zero if it was a pseudo HIT
  */
-int hit_is_real_hit(const struct in6_addr *hit)
+int hit_is_real_hit(const struct in6_addr *const hit)
 {
+    HIP_ASSERT(hit);
     return ipv6_addr_is_hit(hit) && (hit->s6_addr32[3] != 0);
 }
 
@@ -115,8 +119,9 @@
  * @return zero if the IPv6 address was a real HIT and
  * '          one if it was a pseudo HIT
  */
-int hit_is_opportunistic_hit(const struct in6_addr *hit)
+int hit_is_opportunistic_hit(const struct in6_addr *const hit)
 {
+    HIP_ASSERT(hit);
     return ipv6_addr_is_hit(hit) && (hit->s6_addr32[3] == 0);
 }
 
@@ -125,8 +130,9 @@
  *
  * @param hit an IPv6 address for which to set the HIT prefix
  */
-void set_hit_prefix(struct in6_addr *hit)
+void set_hit_prefix(struct in6_addr *const hit)
 {
+    HIP_ASSERT(hit);
     hip_closest_prefix_type hit_begin;
     memcpy(&hit_begin, hit, sizeof(hip_closest_prefix_type));
     hit_begin &= htonl(HIP_HIT_TYPE_MASK_CLEAR);
@@ -139,8 +145,9 @@
  *
  * @param lsi an IPv4 address for which to set the LSI prefix
  */
-void set_lsi_prefix(hip_lsi_t *lsi)
+void set_lsi_prefix(hip_lsi_t *const lsi)
 {
+    HIP_ASSERT(lsi);
     hip_closest_prefix_type lsi_begin;
     memcpy(&lsi_begin, lsi, sizeof(hip_closest_prefix_type));
     lsi_begin &= htonl(HIP_LSI_TYPE_MASK_CLEAR);
@@ -155,9 +162,11 @@
  * @param lsi2 an LSI
  * @return one if the LSIs are equal or zero otherwise
  */
-int hip_lsi_are_equal(const hip_lsi_t *lsi1,
-                      const hip_lsi_t *lsi2)
+int hip_lsi_are_equal(const hip_lsi_t *const lsi1,
+                      const hip_lsi_t *const lsi2)
 {
+    HIP_ASSERT(lsi1);
+    HIP_ASSERT(lsi2);
     return ipv4_addr_cmp(lsi1, lsi2) == 0;
 }
 
@@ -170,11 +179,13 @@
  * @return zero for type match, greater than zero for mismatch or
  * negative on error
  */
-int hip_id_type_match(const struct in6_addr *id, int id_type)
+int hip_id_type_match(const struct in6_addr *const id, const int id_type)
 {
     int       ret = 0, is_lsi = 0, is_hit = 0;
     hip_lsi_t lsi;
 
+    HIP_ASSERT(id);
+
     if (ipv6_addr_is_hit(id)) {
         is_hit = 1;
     } else if (IN6_IS_ADDR_V4MAPPED(id)) {
@@ -210,13 +221,16 @@
  * and Legacy Software and Networks , final project, December 2008</a>
  *
  */
-int hip_opportunistic_ipv6_to_hit(const struct in6_addr *ip,
-                                  struct in6_addr *hit,
-                                  int hit_type)
+int hip_opportunistic_ipv6_to_hit(const struct in6_addr *const ip,
+                                  struct in6_addr *const hit,
+                                  const int hit_type)
 {
     int     err = 0;
     uint8_t digest[HIP_AH_SHA_LEN];
 
+    HIP_ASSERT(ip);
+    HIP_ASSERT(hit);
+
     if (hit_type != HIP_HIT_TYPE_HASH100) {
         return -ENOSYS;
     }
@@ -248,7 +262,7 @@
  *                  NULL if the cast fails.
  */
 
-void *hip_cast_sa_addr(struct sockaddr *sa)
+void *hip_cast_sa_addr(struct sockaddr *const sa)
 {
     if (sa == NULL) {
         HIP_ERROR("sockaddr is NULL, skipping type conversion\n");
@@ -277,6 +291,7 @@
  */
 int hip_sockaddr_is_v6_mapped(const struct sockaddr *const sa)
 {
+    HIP_ASSERT(sa);
     if (sa->sa_family != AF_INET6) {
         return 0;
     } else {
@@ -290,10 +305,12 @@
  * @param sockaddr the sockaddr structure
  * @return the length of the actual sockaddr structure in bytes
  */
-int hip_sockaddr_len(const void *sockaddr)
+int hip_sockaddr_len(const void *const sockaddr)
 {
-    const struct sockaddr *sa = sockaddr;
-    int                    len;
+    const struct sockaddr *const sa = sockaddr;
+    int                          len;
+
+    HIP_ASSERT(sockaddr);
 
     switch (sa->sa_family) {
     case AF_INET:
@@ -317,10 +334,12 @@
  * @param sockaddr the sockaddr structure
  * @return the length of the address field in the @c sockaddr structure
  */
-int hip_sa_addr_len(void *sockaddr)
+int hip_sa_addr_len(void *const sockaddr)
 {
-    struct sockaddr *sa = (struct sockaddr *) sockaddr;
-    int              len;
+    struct sockaddr *const sa = (struct sockaddr *) sockaddr;
+    int                    len;
+
+    HIP_ASSERT(sockaddr);
 
     switch (sa->sa_family) {
     case AF_INET:
@@ -343,16 +362,20 @@
  * @note remember to fill in the port number by yourself
  *       if necessary
  */
-void hip_addr_to_sockaddr(struct in6_addr *addr, struct sockaddr_storage *sa)
+void hip_addr_to_sockaddr(struct in6_addr *const addr,
+                          struct sockaddr_storage *const sa)
 {
+    HIP_ASSERT(addr);
+    HIP_ASSERT(sa);
+
     memset(sa, 0, sizeof(struct sockaddr_storage));
 
     if (IN6_IS_ADDR_V4MAPPED(addr)) {
-        struct sockaddr_in *in = (struct sockaddr_in *) sa;
+        struct sockaddr_in *const in = (struct sockaddr_in *) sa;
         in->sin_family = AF_INET;
         IPV6_TO_IPV4_MAP(addr, &in->sin_addr);
     } else {
-        struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) sa;
+        struct sockaddr_in6 *const in6 = (struct sockaddr_in6 *) sa;
         in6->sin6_family = AF_INET6;
         ipv6_addr_copy(&in6->sin6_addr, addr);
     }
@@ -365,10 +388,12 @@
  * @param addr the address to verify
  * @return one if the address if loopback or zero otherwise
  */
-int hip_addr_is_loopback(struct in6_addr *addr)
+int hip_addr_is_loopback(const struct in6_addr *const addr)
 {
     struct in_addr addr_in;
 
+    HIP_ASSERT(addr);
+
     if (!IN6_IS_ADDR_V4MAPPED(addr)) {
         return IN6_IS_ADDR_LOOPBACK(addr);
     }
@@ -376,18 +401,27 @@
     return IS_IPV4_LOOPBACK(addr_in.s_addr);
 }
 
-int ipv4_addr_cmp(const struct in_addr *a1, const struct in_addr *a2)
+int ipv4_addr_cmp(const struct in_addr *const a1,
+                  const struct in_addr *const a2)
 {
+    HIP_ASSERT(a1);
+    HIP_ASSERT(a2);
     return memcmp(a1, a2, sizeof(struct in_addr));
 }
 
-void ipv4_addr_copy(struct in_addr *dest, const struct in_addr *src)
+void ipv4_addr_copy(struct in_addr *const dest,
+                    const struct in_addr *const src)
 {
+    HIP_ASSERT(dest);
+    HIP_ASSERT(src);
     memcpy(dest, src, sizeof(struct in_addr));
 }
 
-int ipv6_addr_cmp(const struct in6_addr *a1, const struct in6_addr *a2)
+int ipv6_addr_cmp(const struct in6_addr *const a1,
+                  const struct in6_addr *const a2)
 {
+    HIP_ASSERT(a1);
+    HIP_ASSERT(a2);
     return memcmp(a1, a2, sizeof(struct in6_addr));
 }
 
@@ -396,16 +430,17 @@
     memcpy(dest, src, sizeof(struct in6_addr));
 }
 
-int ipv6_addr_any(const struct in6_addr *a)
+int ipv6_addr_any(const struct in6_addr *const a)
 {
+    HIP_ASSERT(a);
     return (a->s6_addr[0] | a->s6_addr[1] | a->s6_addr[2] | a->s6_addr[3] |
             a->s6_addr[4] | a->s6_addr[5] | a->s6_addr[6] | a->s6_addr[7] |
             a->s6_addr[8] | a->s6_addr[9] | a->s6_addr[10] | a->s6_addr[11] |
             a->s6_addr[12] | a->s6_addr[13] | a->s6_addr[14] | a->s6_addr[15]) 
== 0;
 }
 
-void hip_copy_in6addr_null_check(struct in6_addr *to,
-                                 const struct in6_addr *from)
+void hip_copy_in6addr_null_check(struct in6_addr *const to,
+                                 const struct in6_addr *const from)
 {
     HIP_ASSERT(to);
     if (from) {
@@ -415,7 +450,8 @@
     }
 }
 
-void hip_copy_inaddr_null_check(struct in_addr *to, const struct in_addr *from)
+void hip_copy_inaddr_null_check(struct in_addr *const to,
+                                const struct in_addr *const from)
 {
     HIP_ASSERT(to);
     if (from) {

=== modified file 'lib/core/prefix.h'
--- lib/core/prefix.h   2011-04-30 21:36:17 +0000
+++ lib/core/prefix.h   2011-06-08 18:32:15 +0000
@@ -36,36 +36,36 @@
 
 typedef uint32_t hip_closest_prefix_type;
 
-int ipv6_addr_is_hit(const struct in6_addr *hit);
-int ipv6_addr_is_teredo(const struct in6_addr *teredo);
-int ipv6_addr_is_null(const struct in6_addr *ip);
-int hit_is_real_hit(const struct in6_addr *hit);
-int hit_is_opportunistic_hit(const struct in6_addr *hit);
-void set_hit_prefix(struct in6_addr *hit);
-void set_lsi_prefix(hip_lsi_t *lsi);
-int hip_id_type_match(const struct in6_addr *id, int id_type);
-int hip_opportunistic_ipv6_to_hit(const struct in6_addr *ip,
-                                  struct in6_addr *hit, int hit_type);
-void *hip_cast_sa_addr(struct sockaddr *sa);
-int hip_sockaddr_len(const void *sockaddr);
-int hip_sa_addr_len(void *sockaddr);
-void hip_addr_to_sockaddr(struct in6_addr *addr, struct sockaddr_storage *sa);
-int hip_sockaddr_is_v6_mapped(const struct sockaddr *const sa);
-int hip_addr_is_loopback(struct in6_addr *addr);
-int hip_lsi_are_equal(const hip_lsi_t *lsi1,
-                      const hip_lsi_t *lsi2);
+int ipv6_addr_is_hit(const struct in6_addr *const hit);
+int ipv6_addr_is_teredo(const struct in6_addr *const teredo);
+int ipv6_addr_is_null(const struct in6_addr *const ip);
+int hit_is_real_hit(const struct in6_addr *const hit);
+int hit_is_opportunistic_hit(const struct in6_addr *const hit);
+void set_hit_prefix(struct in6_addr *const hit);
+void set_lsi_prefix(hip_lsi_t *const lsi);
+int hip_id_type_match(const struct in6_addr *const id, int id_type);
+int hip_opportunistic_ipv6_to_hit(const struct in6_addr *const ip,
+                                  struct in6_addr *const hit, int hit_type);
+void *hip_cast_sa_addr(struct sockaddr *const sa);
+int hip_sockaddr_len(const void *const sockaddr);
+int hip_sa_addr_len(void *const sockaddr);
+void hip_addr_to_sockaddr(struct in6_addr *const addr, struct sockaddr_storage 
*const sa);
+int hip_sockaddr_is_v6_mapped(const struct sockaddr *const const sa);
+int hip_addr_is_loopback(const struct in6_addr *const addr);
+int hip_lsi_are_equal(const hip_lsi_t *const lsi1,
+                      const hip_lsi_t *const lsi2);
 
-int ipv4_addr_cmp(const struct in_addr *a1,
-                  const struct in_addr *a2);
-void ipv4_addr_copy(struct in_addr *dest, const struct in_addr *src);
-int ipv6_addr_cmp(const struct in6_addr *a1,
-                  const struct in6_addr *a2);
-void ipv6_addr_copy(struct in6_addr *dest, const struct in6_addr *src);
-int ipv6_addr_any(const struct in6_addr *a);
-void hip_copy_in6addr_null_check(struct in6_addr *to,
-                                 const struct in6_addr *from);
-void hip_copy_inaddr_null_check(struct in_addr *to,
-                                const struct in_addr *from);
+int ipv4_addr_cmp(const struct in_addr *const a1,
+                  const struct in_addr *const a2);
+void ipv4_addr_copy(struct in_addr *const dest, const struct in_addr *const 
src);
+int ipv6_addr_cmp(const struct in6_addr *const a1,
+                  const struct in6_addr *const a2);
+void ipv6_addr_copy(struct in6_addr *const dest, const struct in6_addr *const 
src);
+int ipv6_addr_any(const struct in6_addr *const a);
+void hip_copy_in6addr_null_check(struct in6_addr *const to,
+                                 const struct in6_addr *const from);
+void hip_copy_inaddr_null_check(struct in_addr *const to,
+                                const struct in_addr *const from);
 
 /* IN6_IS_ADDR_V4MAPPED(a) is defined in /usr/include/netinet/in.h */
 

=== modified file 'modules/update/hipd/update_param_handling.c'
--- modules/update/hipd/update_param_handling.c 2011-05-18 08:56:19 +0000
+++ modules/update/hipd/update_param_handling.c 2011-06-08 18:41:26 +0000
@@ -326,7 +326,6 @@
     int                                src_addr_included    = 0;
     union hip_locator_info_addr       *locator_info_addr    = NULL;
     struct hip_locator_info_addr_item *locator_address_item = NULL;
-    struct in6_addr                   *peer_addr            = 0;
     struct update_state               *localstate           = NULL;
     struct hip_locator                *locator              = NULL;
 
@@ -354,8 +353,9 @@
 
         for (int i = 0; i < locator_addr_count; i++) {
             locator_info_addr = hip_get_locator_item(locator_address_item, i);
+            const struct in6_addr *const peer_addr = 
hip_get_locator_item_address(locator_info_addr);
 
-            if (!hip_add_address_to_send_echo_request(localstate, 
*hip_get_locator_item_address(locator_info_addr))) {
+            if (!hip_add_address_to_send_echo_request(localstate, *peer_addr)) 
{
                 HIP_ERROR("Adding an address to the container for update 
locators failed!\n");
                 return -1;
             }

Other related posts:

  • » [hipl-dev] [Branch ~hipl-core/hipl/trunk] Rev 5965: Fix bug #789327: - noreply