X-Git-Url: https://bearssl.org/gitweb//home/git/?p=BearSSL;a=blobdiff_plain;f=tools%2Ffiles.c;h=651d51a06f0fb3eb864717eb4e5f900584516418;hp=07af6c4194a7e4e0bf993b6f7cdc16b3d9e43178;hb=b42bd5972f935ffc32019acac6f8a07ae08ae9c2;hpb=3210f38e0491b39aec1ef419cb4114e9483089fb diff --git a/tools/files.c b/tools/files.c index 07af6c4..651d51a 100644 --- a/tools/files.c +++ b/tools/files.c @@ -172,6 +172,7 @@ decode_pem(const void *src, size_t len, size_t *num) bvector bv = VEC_INIT; int inobj; + *num = 0; br_pem_decoder_init(&pc); buf = src; inobj = 0; @@ -267,6 +268,9 @@ read_certificates(const char *fname, size_t *num) pos = decode_pem(buf, len, &num_pos); xfree(buf); + if (pos == NULL) { + return NULL; + } for (u = 0; u < num_pos; u ++) { if (eqstr(pos[u].name, "CERTIFICATE") || eqstr(pos[u].name, "X509 CERTIFICATE")) @@ -296,3 +300,15 @@ read_certificates(const char *fname, size_t *num) VEC_CLEAR(cert_list); return xcs; } + +/* see brssl.h */ +void +free_certificates(br_x509_certificate *certs, size_t num) +{ + size_t u; + + for (u = 0; u < num; u ++) { + xfree(certs[u].data); + } + xfree(certs); +}