fixed destroy() bug

This commit is contained in:
Andreas Steffen
2007-04-14 17:34:41 +00:00
parent 6598f99af0
commit be6258485c
3 changed files with 46 additions and 28 deletions
+39 -13
View File
@@ -21,6 +21,7 @@
* for more details.
*/
#include <library.h>
#include <debug.h>
#include <asn1/asn1.h>
@@ -322,8 +323,40 @@ static err_t is_valid(const private_x509ac_t *this, time_t *until)
*/
static bool parse_directoryName(chunk_t blob, int level, bool implicit, identification_t **name)
{
*name = NULL;
return FALSE;
bool has_directoryName;
linked_list_t *list = linked_list_create();
parse_generalNames(blob, level, implicit, list);
has_directoryName = list->get_count(list) > 0;
if (has_directoryName)
{
iterator_t *iterator = list->create_iterator(list, TRUE);
identification_t *directoryName;
bool first = TRUE;
while (iterator->iterate(iterator, (void**)&directoryName))
{
if (first)
{
*name = directoryName;
first = FALSE;
}
else
{
DBG1("more than one directory name - first selected");
directoryName->destroy(directoryName);
}
}
iterator->destroy(iterator);
}
else
{
DBG1("no directoryName found");
}
list->destroy(list);
return has_directoryName;
}
/**
@@ -403,7 +436,7 @@ static bool parse_certificate(chunk_t blob, private_x509ac_t *this)
}
break;
case AC_OBJ_HOLDER_ISSUER:
if (!parse_directoryName(object, level, FALSE, &this->holderIssuer));
if (!parse_directoryName(object, level, FALSE, &this->holderIssuer))
{
return FALSE;
}
@@ -412,13 +445,13 @@ static bool parse_certificate(chunk_t blob, private_x509ac_t *this)
this->holderSerial = object;
break;
case AC_OBJ_ENTITY_NAME:
if (!parse_directoryName(object, level, FALSE, &this->entityName));
if (!parse_directoryName(object, level, TRUE, &this->entityName))
{
return FALSE;
}
break;
case AC_OBJ_ISSUER_NAME:
if (!parse_directoryName(object, level, FALSE, &this->issuerName));
if (!parse_directoryName(object, level, FALSE, &this->issuerName))
{
return FALSE;
}
@@ -549,18 +582,11 @@ x509ac_t *x509ac_create_from_file(const char *filename)
{
bool pgp = FALSE;
chunk_t chunk = chunk_empty;
x509ac_t *cert = NULL;
if (!pem_asn1_load_file(filename, NULL, "attribute certificate", &chunk, &pgp))
{
return NULL;
}
cert = x509ac_create_from_chunk(chunk);
if (cert == NULL)
{
free(chunk.ptr);
}
return cert;
return x509ac_create_from_chunk(chunk);
}
+3 -7
View File
@@ -494,14 +494,10 @@ crl_t *crl_create_from_file(const char *filename)
{
bool pgp = FALSE;
chunk_t chunk = chunk_empty;
crl_t *crl = NULL;
if (!pem_asn1_load_file(filename, NULL, "crl", &chunk, &pgp))
{
return NULL;
crl = crl_create_from_chunk(chunk);
if (crl == NULL)
free(chunk.ptr);
return crl;
}
return crl_create_from_chunk(chunk);
}
+4 -8
View File
@@ -537,7 +537,7 @@ static identification_t *parse_generalName(chunk_t blob, int level0)
/**
* extracts one or several GNs and puts them into a chained list
*/
static void parse_generalNames(chunk_t blob, int level0, bool implicit, linked_list_t *list)
void parse_generalNames(chunk_t blob, int level0, bool implicit, linked_list_t *list)
{
asn1_ctx_t ctx;
chunk_t object;
@@ -1287,17 +1287,13 @@ x509_t *x509_create_from_file(const char *filename, const char *label)
{
bool pgp = FALSE;
chunk_t chunk = chunk_empty;
x509_t *cert = NULL;
char cert_label[BUF_LEN];
snprintf(cert_label, BUF_LEN, "%s certificate", label);
if (!pem_asn1_load_file(filename, NULL, cert_label, &chunk, &pgp))
{
return NULL;
cert = x509_create_from_chunk(chunk, 0);
if (cert == NULL)
free(chunk.ptr);
return cert;
}
return x509_create_from_chunk(chunk, 0);
}