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.
This commit is contained in:
Daniel Willmann 2015-11-23 15:49:29 +01:00
parent ec0e50e148
commit 53018e937c
1 changed files with 2 additions and 2 deletions

View File

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