From: Nikos Mavrogiannopoulos Date: Thu, 13 Feb 2014 12:28:20 +0000 (+0100) Subject: ensure that _gnutls_x509_read_value works as documented. X-Git-Tag: gnutls_3_3_0pre0~185 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=ac95c5a3488759e68b61dbab70c586fafa42ee21;p=thirdparty%2Fgnutls.git ensure that _gnutls_x509_read_value works as documented. --- diff --git a/lib/x509/common.c b/lib/x509/common.c index 3c56ee8dae..8bde558708 100644 --- a/lib/x509/common.c +++ b/lib/x509/common.c @@ -1023,8 +1023,7 @@ _gnutls_x509_read_value(ASN1_TYPE c, const char *root, } if (etype == ASN1_ETYPE_BIT_STRING) { - len /= 8; - len++; + len = (len + 7)/8; } tmp = gnutls_malloc((size_t) len + 1); @@ -1042,12 +1041,11 @@ _gnutls_x509_read_value(ASN1_TYPE c, const char *root, } if (etype == ASN1_ETYPE_BIT_STRING) { - ret->size = len / 8; - if (len % 8 > 0) - ret->size++; + ret->size = (len+7) / 8; } else ret->size = (unsigned) len; + tmp[ret->size] = 0; ret->data = tmp; return 0;