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.
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 @@
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;
}