aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Willmann <dwillmann@sysmocom.de>2015-11-23 15:49:29 +0100
committerDaniel Willmann <dwillmann@sysmocom.de>2015-11-23 15:55:46 +0100
commit53018e937cf3f07c19dbc4e58ffad699213d408f (patch)
tree849075eb1d8e5ca1ac47e540ec64062129a7c348 /src
parentec0e50e1481a8905ba0998fc07fd62b8ac2acfb0 (diff)
asn1helpers: Ensure that string is NULL-terminated
The buf in an OCTET_STRING_t is not (necessarily) NULL-terminated, so make sure there is a terminating NULL byte at the end in the resulting string.
Diffstat (limited to 'src')
-rw-r--r--src/asn1helpers.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/asn1helpers.c b/src/asn1helpers.c
index 2a1b187..e59d5a9 100644
--- a/src/asn1helpers.c
+++ b/src/asn1helpers.c
@@ -41,13 +41,13 @@ void asn1_u24_to_bitstring(BIT_STRING_t *bitstr, uint32_t *in)
int asn1_strncpy(char *out, const OCTET_STRING_t *in, size_t n)
{
- size_t cpylen = n;
+ size_t cpylen = n-1;
if (in->size < cpylen)
cpylen = in->size;
strncpy(out, (char *)in->buf, cpylen);
- out[n-1] = '\0';
+ out[cpylen] = '\0';
return cpylen;
}