summaryrefslogtreecommitdiff
path: root/src/libstrongswan/chunk.c
diff options
context:
space:
mode:
authorRene Mayrhofer <rene@mayrhofer.eu.org>2008-10-29 20:30:44 +0000
committerRene Mayrhofer <rene@mayrhofer.eu.org>2008-10-29 20:30:44 +0000
commit74f0bbfc53cb5fa519e4e27ece53735ab51b397c (patch)
tree0dbab9c835be15577ff05b474b6361bb326d66ce /src/libstrongswan/chunk.c
parent5c1fa2516bda1ccf8eb00178c0beb196c2020a94 (diff)
downloadvyos-strongswan-74f0bbfc53cb5fa519e4e27ece53735ab51b397c.tar.gz
vyos-strongswan-74f0bbfc53cb5fa519e4e27ece53735ab51b397c.zip
- New upstream release.
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);
}