From 9f7c426d5a6bfb0e60895a690ed835c47e04cb4e Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Mon, 8 Jul 2013 16:30:52 +0200 Subject: asn1: In p11_asn1_read() allocate an extra null terminator As a courtesy for callers. --- trust/asn1.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'trust') 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; } -- cgit v1.1