summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2015-04-20 16:05:23 +0200
committerNikos Mavrogiannopoulos <nmav@redhat.com>2015-04-20 16:13:54 +0200
commit49924c02fed91580839b17686345406b232ea812 (patch)
treec535475cbf4c60d3afeaf5a8061c2206919f58ff /src
parenta9c908190324bbaadff2031421e23adfba014a2a (diff)
downloadlibtasn1-49924c02fed91580839b17686345406b232ea812.tar.gz
asn1Decoding: added a debug flag which enforces strict memory alignment
Diffstat (limited to 'src')
-rw-r--r--src/asn1Decoding.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/asn1Decoding.c b/src/asn1Decoding.c
index 8ef058d..b52e791 100644
--- a/src/asn1Decoding.c
+++ b/src/asn1Decoding.c
@@ -72,6 +72,7 @@ main (int argc, char *argv[])
static const struct option long_options[] = {
{"help", no_argument, 0, 'h'},
{"strict", no_argument, 0, 's'},
+ {"debug", no_argument, 0, 'd'},
{"benchmark", no_argument, 0, 'b'},
{"version", no_argument, 0, 'v'},
{0, 0, 0, 0}
@@ -86,7 +87,7 @@ main (int argc, char *argv[])
int asn1_result = ASN1_SUCCESS;
unsigned char *der;
int der_len = 0, benchmark = 0;
- int strict = 0;
+ int strict = 0, debug = 0;
/* FILE *outputFile; */
set_program_name (argv[0]);
@@ -97,7 +98,7 @@ main (int argc, char *argv[])
{
option_result =
- getopt_long (argc, argv, "hbsvc", long_options, &option_index);
+ getopt_long (argc, argv, "hbdsvc", long_options, &option_index);
if (option_result == -1)
break;
@@ -110,6 +111,9 @@ main (int argc, char *argv[])
case 'b':
benchmark = 1;
break;
+ case 'd':
+ debug = 1;
+ break;
case 's':
strict = 1;
break;
@@ -182,6 +186,12 @@ main (int argc, char *argv[])
der_len = tmplen;
}
+ /* read_binary_file() returns a buffer with more data than required,
+ * with this reallocation we ensure that memory accesses outside the
+ * boundaries are detected */
+ if (der != NULL && debug != 0)
+ der = realloc(der, der_len);
+
if (der == NULL)
{
fprintf (stderr, "asn1Decoding: could not read '%s'\n",
@@ -194,7 +204,6 @@ main (int argc, char *argv[])
exit (1);
}
-
/*****************************************/
/* ONLY FOR TEST */
/*****************************************/