summaryrefslogtreecommitdiff
path: root/src/libstrongswan/chunk.c
diff options
context:
space:
mode:
authorRene Mayrhofer <rene@mayrhofer.eu.org>2008-10-29 11:11:01 +0000
committerRene Mayrhofer <rene@mayrhofer.eu.org>2008-10-29 11:11:01 +0000
commit8b80ab5a6950ce6515f477624794defd7531642a (patch)
treeaa8303f3806c5615fbeafc4dc82febe3cd7c24dc /src/libstrongswan/chunk.c
parentdb67c87db3c9089ea8d2e14f617bf3d9e2af261f (diff)
downloadvyos-strongswan-8b80ab5a6950ce6515f477624794defd7531642a.tar.gz
vyos-strongswan-8b80ab5a6950ce6515f477624794defd7531642a.zip
[svn-upgrade] Integrating new upstream version, strongswan (4.2.8)
Diffstat (limited to 'src/libstrongswan/chunk.c')
-rw-r--r--src/libstrongswan/chunk.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/libstrongswan/chunk.c b/src/libstrongswan/chunk.c
index 7e7a7c69d..565f48fb0 100644
--- a/src/libstrongswan/chunk.c
+++ b/src/libstrongswan/chunk.c
@@ -13,7 +13,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: chunk.c 3868 2008-04-24 13:26:22Z martin $
+ * $Id: chunk.c 4276 2008-08-22 10:44:51Z martin $
*/
#include <stdio.h>
@@ -298,16 +298,28 @@ static char hex2bin(char hex)
chunk_t chunk_from_hex(chunk_t hex, char *buf)
{
int i, len;
+ bool odd = FALSE;
- len = hex.len / 2;
+ len = (hex.len / 2);
+ if (hex.len % 2)
+ {
+ odd = TRUE;
+ len++;
+ }
if (!buf)
{
buf = malloc(len);
}
- for (i = 0; i < len; i++)
+ /* buffer is filled from the right */
+ memset(buf, 0, len);
+ hex.ptr += hex.len;
+ for (i = len - 1; i >= 0; i--)
{
- buf[i] = hex2bin(*hex.ptr++) << 4;
- buf[i] |= hex2bin(*hex.ptr++);
+ buf[i] = hex2bin(*(--hex.ptr));
+ if (i > 0 || !odd)
+ {
+ buf[i] |= hex2bin(*(--hex.ptr)) << 4;
+ }
}
return chunk_create(buf, len);
}