summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stef@thewalter.net>2013-07-08 16:30:52 +0200
committerStef Walter <stef@thewalter.net>2013-07-08 16:30:52 +0200
commit9f7c426d5a6bfb0e60895a690ed835c47e04cb4e (patch)
tree8933e79c6b90522aa03f8447c8dd36e868793831
parent09ece36663a3672dfa2db97029cfd5f5360188e8 (diff)
downloadp11-kit-9f7c426d5a6bfb0e60895a690ed835c47e04cb4e.tar.gz
asn1: In p11_asn1_read() allocate an extra null terminator
As a courtesy for callers.
-rw-r--r--trust/asn1.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/trust/asn1.c b/trust/asn1.c
index fcd8e1c..653d816 100644
--- a/trust/asn1.c
+++ b/trust/asn1.c
@@ -197,7 +197,7 @@ p11_asn1_read (node_asn *asn,
const char *field,
size_t *length)
{
- void *value;
+ unsigned char *value;
int len;
int ret;
@@ -212,12 +212,15 @@ p11_asn1_read (node_asn *asn,
return_val_if_fail (ret == ASN1_MEM_ERROR, NULL);
- value = malloc (len);
+ value = malloc (len + 1);
return_val_if_fail (value != NULL, NULL);
ret = asn1_read_value (asn, field, value, &len);
return_val_if_fail (ret == ASN1_SUCCESS, NULL);
+ /* Courtesy zero terminated */
+ value[len] = '\0';
+
*length = len;
return value;
}