[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[SCM] GNU libtasn1 branch, master, updated. libtasn1_3_4-26-g0463d4e
From: |
Nikos Mavrogiannopoulos |
Subject: |
[SCM] GNU libtasn1 branch, master, updated. libtasn1_3_4-26-g0463d4e |
Date: |
Sat, 26 Apr 2014 09:58:55 +0000 |
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU libtasn1".
http://git.savannah.gnu.org/cgit/libtasn1.git/commit/?id=0463d4e6349581f4d5a2503a911886e0ce866091
The branch, master has been updated
via 0463d4e6349581f4d5a2503a911886e0ce866091 (commit)
via f30d56d35d47a4377a393ba89c708fa61bd3a78f (commit)
via 3317187de6d7d636b33b470691ef0a2be3b81d37 (commit)
via 84288b43c80e7f555c1a0a2ed6b4f22bcdf6be41 (commit)
via 057193dcc2089520ab36d95f42d12f4ffd8127b5 (commit)
via 2ce0f82c5d09c348d2f41bad9bc6d9ae0e9b08d3 (commit)
from f755119f1ab7b7b90fc14a148e0e2bb62123f80f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 0463d4e6349581f4d5a2503a911886e0ce866091
Author: Nikos Mavrogiannopoulos <address@hidden>
Date: Sat Apr 26 11:58:01 2014 +0200
Added test that decodes and re-encodes a DER CRL.
commit f30d56d35d47a4377a393ba89c708fa61bd3a78f
Author: Nikos Mavrogiannopoulos <address@hidden>
Date: Tue Apr 22 00:46:53 2014 +0200
doc update
commit 3317187de6d7d636b33b470691ef0a2be3b81d37
Author: Kurt Roeckx <address@hidden>
Date: Sun Apr 20 16:50:03 2014 +0200
Fix memory leak.
commit 84288b43c80e7f555c1a0a2ed6b4f22bcdf6be41
Author: Kurt Roeckx <address@hidden>
Date: Sun Apr 20 16:50:02 2014 +0200
_asn1_ordering_*(): Fix memory leak in case of error
commit 057193dcc2089520ab36d95f42d12f4ffd8127b5
Author: Kurt Roeckx <address@hidden>
Date: Sun Apr 20 16:50:01 2014 +0200
Make _asn1_ordering_* return error values and check them.
commit 2ce0f82c5d09c348d2f41bad9bc6d9ae0e9b08d3
Author: Kurt Roeckx <address@hidden>
Date: Sun Apr 20 16:50:00 2014 +0200
Call ordering functions with the right length
We're going to insert the length of the set and at this point are going to
order
it. But we called it with the wrong length. Also updates the check to
only do
it when the buffer isn't to small.
-----------------------------------------------------------------------
Summary of changes:
NEWS | 1 +
lib/ASN1.c | 2 +-
lib/coding.c | 100 +++++++++++++++++++++-------
tests/Makefile.am | 8 ++-
tests/{Test_indefinite.c => Test_encdec.c} | 39 ++++++++---
tests/Test_tree.c | 3 +
tests/crl.der | Bin 0 -> 504 bytes
7 files changed, 113 insertions(+), 40 deletions(-)
copy tests/{Test_indefinite.c => Test_encdec.c} (76%)
create mode 100644 tests/crl.der
diff --git a/NEWS b/NEWS
index 6fae21a..cb36265 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ GNU Libtasn1 NEWS -*-
outline -*-
- Correctly handle decoding of recursive CHOICE options.
- Allow deleting elements of SET OF. Patch by Jean-Louis Thekekara.
- Several small bug fixes found by coverity.
+- Code improvements contributed by Kurt Roeckx.
* Noteworthy changes in release 3.4 (released 2013-11-25) [stable]
- Added asn1_delete_structure2() which allows zeroizing the contents
diff --git a/lib/ASN1.c b/lib/ASN1.c
index 23c0ff4..ef58f95 100644
--- a/lib/ASN1.c
+++ b/lib/ASN1.c
@@ -73,7 +73,7 @@
#line 1 "ASN1.y"
/*
- * Copyright (C) 2001-2013 Free Software Foundation, Inc.
+ * Copyright (C) 2001-2014 Free Software Foundation, Inc.
*
* This file is part of LIBTASN1.
*
diff --git a/lib/coding.c b/lib/coding.c
index e640c0b..4ed033f 100644
--- a/lib/coding.c
+++ b/lib/coding.c
@@ -327,7 +327,8 @@ _asn1_get_utctime_der(unsigned char *der,int
*der_len,unsigned char *str)
/* must store the length of DER. */
/* Return: */
/* ASN1_MEM_ERROR when DER isn't big enough */
-/* ASN1_SUCCESS otherwise */
+/* ASN1_SUCCESS if succesful */
+/* or an error value. */
/******************************************************/
static int
_asn1_objectid_der (unsigned char *str, unsigned char *der, int *der_len)
@@ -695,8 +696,10 @@ _asn1_insert_tag_der (asn1_node node, unsigned char *der,
int *counter,
/* der: string with the DER coding. */
/* node: pointer to the SET element. */
/* Return: */
+/* ASN1_SUCCESS if successful */
+/* or an error value. */
/******************************************************/
-static void
+static int
_asn1_ordering_set (unsigned char *der, int der_len, asn1_node node)
{
struct vet
@@ -711,11 +714,12 @@ _asn1_ordering_set (unsigned char *der, int der_len,
asn1_node node)
asn1_node p;
unsigned char class, *temp;
unsigned long tag, t;
+ int err;
counter = 0;
if (type_field (node->type) != ASN1_ETYPE_SET)
- return;
+ return ASN1_VALUE_NOT_VALID;
p = node->down;
while (p && ((type_field (p->type) == ASN1_ETYPE_TAG) ||
@@ -723,14 +727,17 @@ _asn1_ordering_set (unsigned char *der, int der_len,
asn1_node node)
p = p->right;
if ((p == NULL) || (p->right == NULL))
- return;
+ return ASN1_SUCCESS;
first = last = NULL;
while (p)
{
p_vet = malloc (sizeof (struct vet));
if (p_vet == NULL)
- return;
+ {
+ err = ASN1_MEM_ALLOC_ERROR;
+ goto error;
+ }
p_vet->next = NULL;
p_vet->prev = last;
@@ -741,10 +748,10 @@ _asn1_ordering_set (unsigned char *der, int der_len,
asn1_node node)
last = p_vet;
/* tag value calculation */
- if (asn1_get_tag_der
- (der + counter, der_len - counter, &class, &len2,
- &tag) != ASN1_SUCCESS)
- return;
+ err = asn1_get_tag_der (der + counter, der_len - counter, &class, &len2,
+ &tag);
+ if (err != ASN1_SUCCESS)
+ goto error;
t = class << 24;
p_vet->value = t | tag;
@@ -753,7 +760,10 @@ _asn1_ordering_set (unsigned char *der, int der_len,
asn1_node node)
/* extraction and length */
len2 = asn1_get_length_der (der + counter, der_len - counter, &len);
if (len2 < 0)
- return;
+ {
+ err = ASN1_DER_ERROR;
+ goto error;
+ }
counter += len + len2;
p_vet->end = counter;
@@ -773,7 +783,10 @@ _asn1_ordering_set (unsigned char *der, int der_len,
asn1_node node)
/* change position */
temp = malloc (p_vet->end - counter);
if (temp == NULL)
- return;
+ {
+ err = ASN1_MEM_ALLOC_ERROR;
+ goto error;
+ }
memcpy (temp, der + counter, p_vet->end - counter);
memcpy (der + counter, der + p_vet->end,
@@ -801,6 +814,16 @@ _asn1_ordering_set (unsigned char *der, int der_len,
asn1_node node)
free (p_vet);
p_vet = first;
}
+ return ASN1_SUCCESS;
+
+error:
+ while (first != NULL)
+ {
+ p_vet = first;
+ first = first->next;
+ free(p_vet);
+ }
+ return err;
}
/******************************************************/
@@ -811,8 +834,10 @@ _asn1_ordering_set (unsigned char *der, int der_len,
asn1_node node)
/* der: string with the DER coding. */
/* node: pointer to the SET OF element. */
/* Return: */
+/* ASN1_SUCCESS if successful */
+/* or an error value. */
/******************************************************/
-static void
+static int
_asn1_ordering_set_of (unsigned char *der, int der_len, asn1_node node)
{
struct vet
@@ -826,27 +851,30 @@ _asn1_ordering_set_of (unsigned char *der, int der_len,
asn1_node node)
asn1_node p;
unsigned char *temp, class;
unsigned long k, max;
+ int err;
counter = 0;
if (type_field (node->type) != ASN1_ETYPE_SET_OF)
- return;
+ return ASN1_VALUE_NOT_VALID;
p = node->down;
while (p && ((type_field (p->type) == ASN1_ETYPE_TAG) ||
(type_field (p->type) == ASN1_ETYPE_SIZE)))
p = p->right;
- p = p->right;
if ((p == NULL) || (p->right == NULL))
- return;
+ return ASN1_SUCCESS;
first = last = NULL;
while (p)
{
p_vet = malloc (sizeof (struct vet));
if (p_vet == NULL)
- return;
+ {
+ err = ASN1_MEM_ALLOC_ERROR;
+ goto error;
+ }
p_vet->next = NULL;
p_vet->prev = last;
@@ -860,15 +888,18 @@ _asn1_ordering_set_of (unsigned char *der, int der_len,
asn1_node node)
if (der_len - counter > 0)
{
- if (asn1_get_tag_der
- (der + counter, der_len - counter, &class, &len,
- NULL) != ASN1_SUCCESS)
- return;
+ err = asn1_get_tag_der (der + counter, der_len - counter, &class,
+ &len, NULL);
+ if (err != ASN1_SUCCESS)
+ goto error;
counter += len;
len2 = asn1_get_length_der (der + counter, der_len - counter, &len);
if (len2 < 0)
- return;
+ {
+ err = ASN1_DER_ERROR;
+ goto error;
+ }
counter += len + len2;
}
@@ -911,7 +942,10 @@ _asn1_ordering_set_of (unsigned char *der, int der_len,
asn1_node node)
/* change position */
temp = malloc (p_vet->end - counter);
if (temp == NULL)
- return;
+ {
+ err = ASN1_MEM_ALLOC_ERROR;
+ goto error;
+ }
memcpy (temp, der + counter, (p_vet->end) - counter);
memcpy (der + counter, der + (p_vet->end),
@@ -935,6 +969,16 @@ _asn1_ordering_set_of (unsigned char *der, int der_len,
asn1_node node)
free (p_vet);
p_vet = first;
}
+ return ASN1_SUCCESS;
+
+error:
+ while (first != NULL)
+ {
+ p_vet = first;
+ first = first->next;
+ free(p_vet);
+ }
+ return err;
}
/**
@@ -1167,7 +1211,11 @@ asn1_der_coding (asn1_node element, const char *name,
void *ider, int *len,
len2 = _asn1_strtol (p->value, NULL, 10);
_asn1_set_value (p, NULL, 0);
if ((type_field (p->type) == ASN1_ETYPE_SET) && (max_len >= 0))
- _asn1_ordering_set (der + len2, max_len - len2, p);
+ {
+ err = _asn1_ordering_set (der + len2, counter - len2, p);
+ if (err != ASN1_SUCCESS)
+ goto error;
+ }
asn1_length_der (counter - len2, temp, &len3);
max_len -= len3;
if (max_len >= 0)
@@ -1207,9 +1255,11 @@ asn1_der_coding (asn1_node element, const char *name,
void *ider, int *len,
len2 = _asn1_strtol (p->value, NULL, 10);
_asn1_set_value (p, NULL, 0);
if ((type_field (p->type) == ASN1_ETYPE_SET_OF)
- && (max_len - len2 > 0))
+ && (counter - len2 > 0) && (max_len >= 0))
{
- _asn1_ordering_set_of (der + len2, max_len - len2, p);
+ err = _asn1_ordering_set_of (der + len2, counter - len2, p);
+ if (err != ASN1_SUCCESS)
+ goto error;
}
asn1_length_der (counter - len2, temp, &len3);
max_len -= len3;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 216828f..0277c70 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -26,7 +26,7 @@ EXTRA_DIST = Test_parser.asn Test_tree.asn
Test_tree_asn1_tab.c \
Test_encoding.asn pkix.asn TestIndef.p12 choice.asn
# For crlf.
-EXTRA_DIST += crlf.cer
+EXTRA_DIST += crlf.cer crl.der
dist_check_SCRIPTS = crlf benchmark
dist_check_SCRIPTS += threadsafety
@@ -34,17 +34,19 @@ dist_check_SCRIPTS += threadsafety
MOSTLYCLEANFILES = Test_parser_ERROR.asn
check_PROGRAMS = Test_parser Test_tree Test_encoding Test_indefinite \
- Test_errors Test_simple Test_overflow Test_strings Test_choice
+ Test_errors Test_simple Test_overflow Test_strings Test_choice \
+ Test_encdec
TESTS = Test_parser Test_tree Test_encoding Test_indefinite \
Test_errors Test_simple Test_overflow crlf threadsafety \
- Test_strings Test_choice
+ Test_strings Test_choice Test_encdec
TESTS_ENVIRONMENT = \
ASN1PARSER=$(srcdir)/Test_parser.asn \
ASN1TREE=$(srcdir)/Test_tree.asn \
ASN1PKIX=$(srcdir)/pkix.asn \
ASN1PKIX=$(srcdir)/pkix.asn \
+ ASN1CRLDER=$(srcdir)/crl.der \
ASN1INDEF=$(srcdir)/TestIndef.p12 \
ASN1ENCODING=$(srcdir)/Test_encoding.asn \
THREADSAFETY_FILES=`find $(top_srcdir)/lib -name \*.c` \
diff --git a/tests/Test_indefinite.c b/tests/Test_encdec.c
similarity index 76%
copy from tests/Test_indefinite.c
copy to tests/Test_encdec.c
index c1613ef..363f2ff 100644
--- a/tests/Test_indefinite.c
+++ b/tests/Test_encdec.c
@@ -40,14 +40,16 @@ int
main (int argc, char *argv[])
{
int result;
- char buffer[10 * 1024];
+ char buffer[5 * 1024];
+ char buffer2[5 * 1024];
asn1_node definitions = NULL;
asn1_node asn1_element = NULL;
char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
FILE *out, *fd;
ssize_t size;
+ int size2;
const char *treefile = getenv ("ASN1PKIX");
- const char *indeffile = getenv ("ASN1INDEF");
+ const char *derfile = getenv ("ASN1CRLDER");
int verbose = 0;
if (argc > 1)
@@ -56,8 +58,8 @@ main (int argc, char *argv[])
if (!treefile)
treefile = "pkix.asn";
- if (!indeffile)
- indeffile = "TestIndef.p12";
+ if (!derfile)
+ derfile = "crl.der";
if (verbose)
{
@@ -68,7 +70,7 @@ main (int argc, char *argv[])
}
/* Check version */
- if (asn1_check_version ("0.2.11") == NULL)
+ if (asn1_check_version ("0.3.3") == NULL)
printf ("\nLibrary version check ERROR:\n actual version: %s\n\n",
asn1_check_version (NULL));
@@ -82,27 +84,27 @@ main (int argc, char *argv[])
out = stdout;
- fd = fopen (indeffile, "rb");
+ fd = fopen (derfile, "rb");
if (fd == NULL)
{
- printf ("Cannot read file %s\n", indeffile);
+ printf ("Cannot read file %s\n", derfile);
exit (1);
}
size = fread (buffer, 1, sizeof (buffer), fd);
if (size <= 0)
{
- printf ("Cannot read from file %s\n", indeffile);
+ printf ("Cannot read from file %s\n", derfile);
exit (1);
}
fclose (fd);
result =
- asn1_create_element (definitions, "PKIX1.pkcs-12-PFX", &asn1_element);
+ asn1_create_element (definitions, "PKIX1.CertificateList", &asn1_element);
if (result != ASN1_SUCCESS)
{
asn1_perror (result);
- printf ("Cannot create PKCS12 element\n");
+ printf ("Cannot create CRL element\n");
exit (1);
}
@@ -110,10 +112,25 @@ main (int argc, char *argv[])
if (result != ASN1_SUCCESS)
{
asn1_perror (result);
- printf ("Cannot decode BER data (size %ld)\n", (long) size);
+ printf ("Cannot decode DER data (size %ld)\n", (long) size);
exit (1);
}
+ size2 = sizeof(buffer2);
+ result = asn1_der_coding (asn1_element, "", buffer2, &size2, NULL);
+ if (result != ASN1_SUCCESS)
+ {
+ asn1_perror (result);
+ printf ("Cannot encode data (size %ld)\n", (long) size);
+ exit (1);
+ }
+
+ if (size2 != size || memcmp(buffer, buffer2, size) != 0)
+ {
+ printf("DER encoded data differ!\n");
+ exit(1);
+ }
+
/* Clear the definition structures */
asn1_delete_structure (&definitions);
asn1_delete_structure (&asn1_element);
diff --git a/tests/Test_tree.c b/tests/Test_tree.c
index c5ef6e5..fce392e 100644
--- a/tests/Test_tree.c
+++ b/tests/Test_tree.c
@@ -84,6 +84,7 @@ test_type test_array[] = {
{ACT_ENCODING, "", 0, 4, ASN1_MEM_ERROR, __LINE__},
{ACT_ENCODING, "", 0, 5, ASN1_SUCCESS, __LINE__},
{ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
+ {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
{ACT_CREATE, "TEST_TREE.KrbError", 0, 0, ASN1_SUCCESS, __LINE__},
{ACT_DECODING, 0, 0, 0, ASN1_SUCCESS, __LINE__},
{ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
@@ -398,11 +399,13 @@ test_type test_array[] = {
{ACT_ENCODING, "", 0, 24, ASN1_MEM_ERROR, __LINE__},
{ACT_ENCODING, "", 0, 25, ASN1_SUCCESS, __LINE__},
{ACT_PRINT_DER, 0, 0, 0, ASN1_SUCCESS, __LINE__},
+ {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
{ACT_CREATE, "TEST_TREE.Sequence1", 0, 0, ASN1_SUCCESS, __LINE__},
{ACT_DECODING_ELEMENT, "int2", 0, 0, ASN1_SUCCESS, __LINE__},
{ACT_VISIT, "", "", ASN1_PRINT_ALL, ASN1_SUCCESS, __LINE__},
{ACT_READ, "int2", "\x0a", 1, ASN1_SUCCESS, __LINE__},
{ACT_READ_LENGTH, "int2", NULL, 1, ASN1_MEM_ERROR, __LINE__},
+ {ACT_DELETE, "", "", 0, ASN1_SUCCESS, __LINE__},
{ACT_CREATE, "TEST_TREE.Sequence1", 0, 0, ASN1_SUCCESS, __LINE__},
{ACT_DECODING, 0, 0, 0, ASN1_SUCCESS, __LINE__},
{ACT_DECODING_START_END, "seq.?2", "START", 10, ASN1_SUCCESS, __LINE__},
diff --git a/tests/crl.der b/tests/crl.der
new file mode 100644
index 0000000..7ab7752
Binary files /dev/null and b/tests/crl.der differ
hooks/post-receive
--
GNU libtasn1
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [SCM] GNU libtasn1 branch, master, updated. libtasn1_3_4-26-g0463d4e,
Nikos Mavrogiannopoulos <=