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:
parent
ec0e50e148
commit
53018e937c
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue