diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-08-25 09:38:23 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-08-25 09:38:23 +0000 |
commit | 33fb3038d0bf6e4b8f234bc10e4bc89441b1dc26 (patch) | |
tree | e2258de2cfbf5ccebabd12317a3ef4f309f42465 /src/gns/plugin_gnsrecord_gns.c | |
parent | a741a84289724ea33d3941b10c57e554e8ab5e09 (diff) | |
download | gnunet-33fb3038d0bf6e4b8f234bc10e4bc89441b1dc26.tar.gz gnunet-33fb3038d0bf6e4b8f234bc10e4bc89441b1dc26.zip |
-fix unaligned access
Diffstat (limited to 'src/gns/plugin_gnsrecord_gns.c')
-rw-r--r-- | src/gns/plugin_gnsrecord_gns.c | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/src/gns/plugin_gnsrecord_gns.c b/src/gns/plugin_gnsrecord_gns.c index 756034d6e..360500af7 100644 --- a/src/gns/plugin_gnsrecord_gns.c +++ b/src/gns/plugin_gnsrecord_gns.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2013, 2014 GNUnet e.V. | 3 | Copyright (C) 2013, 2014, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -93,41 +93,47 @@ gns_value_to_string (void *cls, | |||
93 | } | 93 | } |
94 | case GNUNET_GNSRECORD_TYPE_VPN: | 94 | case GNUNET_GNSRECORD_TYPE_VPN: |
95 | { | 95 | { |
96 | const struct GNUNET_TUN_GnsVpnRecord *vpn; | 96 | struct GNUNET_TUN_GnsVpnRecord vpn; |
97 | char* vpn_str; | 97 | char* vpn_str; |
98 | 98 | ||
99 | cdata = data; | 99 | cdata = data; |
100 | if ( (data_size <= sizeof (struct GNUNET_TUN_GnsVpnRecord)) || | 100 | if ( (data_size <= sizeof (vpn)) || |
101 | ('\0' != cdata[data_size - 1]) ) | 101 | ('\0' != cdata[data_size - 1]) ) |
102 | return NULL; /* malformed */ | 102 | return NULL; /* malformed */ |
103 | vpn = data; | 103 | /* need to memcpy for alignment */ |
104 | memcpy (&vpn, | ||
105 | data, | ||
106 | sizeof (vpn)); | ||
104 | GNUNET_asprintf (&vpn_str, | 107 | GNUNET_asprintf (&vpn_str, |
105 | "%u %s %s", | 108 | "%u %s %s", |
106 | (unsigned int) ntohs (vpn->proto), | 109 | (unsigned int) ntohs (vpn.proto), |
107 | (const char*) GNUNET_i2s_full (&vpn->peer), | 110 | (const char*) GNUNET_i2s_full (&vpn.peer), |
108 | (const char*) &vpn[1]); | 111 | (const char*) &cdata[sizeof (vpn)]); |
109 | return vpn_str; | 112 | return vpn_str; |
110 | } | 113 | } |
111 | case GNUNET_GNSRECORD_TYPE_BOX: | 114 | case GNUNET_GNSRECORD_TYPE_BOX: |
112 | { | 115 | { |
113 | const struct GNUNET_GNSRECORD_BoxRecord *box; | 116 | struct GNUNET_GNSRECORD_BoxRecord box; |
114 | uint32_t rt; | 117 | uint32_t rt; |
115 | char *box_str; | 118 | char *box_str; |
116 | char *ival; | 119 | char *ival; |
117 | 120 | ||
121 | cdata = data; | ||
118 | if (data_size < sizeof (struct GNUNET_GNSRECORD_BoxRecord)) | 122 | if (data_size < sizeof (struct GNUNET_GNSRECORD_BoxRecord)) |
119 | return NULL; /* malformed */ | 123 | return NULL; /* malformed */ |
120 | box = data; | 124 | memcpy (&box, |
121 | rt = ntohl (box->record_type); | 125 | data, |
126 | sizeof (box)); | ||
127 | rt = ntohl (box.record_type); | ||
122 | ival = GNUNET_GNSRECORD_value_to_string (rt, | 128 | ival = GNUNET_GNSRECORD_value_to_string (rt, |
123 | &box[1], | 129 | &cdata[sizeof (box)], |
124 | data_size - sizeof (struct GNUNET_GNSRECORD_BoxRecord)); | 130 | data_size - sizeof (box)); |
125 | if (NULL == ival) | 131 | if (NULL == ival) |
126 | return NULL; /* malformed */ | 132 | return NULL; /* malformed */ |
127 | GNUNET_asprintf (&box_str, | 133 | GNUNET_asprintf (&box_str, |
128 | "%u %u %u %s", | 134 | "%u %u %u %s", |
129 | (unsigned int) ntohs (box->protocol), | 135 | (unsigned int) ntohs (box.protocol), |
130 | (unsigned int) ntohs (box->service), | 136 | (unsigned int) ntohs (box.service), |
131 | (unsigned int) rt, | 137 | (unsigned int) rt, |
132 | ival); | 138 | ival); |
133 | GNUNET_free (ival); | 139 | GNUNET_free (ival); |