Please consider the following patch.
Check for errors reading the assignment file in asn1Coding.
src/asn1Coding.c: Check the value returned by readAssignment ()
to be either ASSIGNMENT_SUCCESS or ASSIGNMENT_EOF.
Currently, the return value of readAssignment () is only
compared to ASSIGNMENT_SUCCESS; ASSIGNMENT_ERROR is treated
identically to ASSIGNMENT_EOF. Cf.:
$ cat < asn1
Example DEFINITIONS EXPLICIT TAGS ::=
BEGIN
Foo ::= OCTET STRING
END
$ asn1Coding-new -o /dev/null asn1 <(printf %s\\n 'x Example.Foo' "''"))
Parse: done.
var=x, value=Example.Foo
asn1Coding: error reading assignment file
$ asn1Coding-old -o /dev/null asn1 <(printf %s\\n 'x Example.Foo' "''"))
Parse: done.
var=x, value=Example.Foo
name:NULL type:OCT_STR
Coding: VALUE_NOT_FOUND
asn1Coding: :: value of element 'ROOT' not found
$
(Though perhaps the code should discern syntax errors from I/O
ones, and report the former as such.)
Two more deficiencies of the reading code are:
• the input is read in /tokens/, not /lines/, thus the following
are equivalent (and there's no way to specify an empty string
or a string with a blank as the value, etc.):
x Example.Foo
'' bar
x
Example.Foo ''
bar
x Example.Foo '' bar
• the code uses static buffers (varName[], value[]), but nowhere
reading is limited to their respective sizes.
I hope to provide a patch replacing fixing these issues (via
replacing fscanf () with fgets () and strsep ()) shortly.
--
FSF associate member #7257
diff --git a/src/asn1Coding.c b/src/asn1Coding.c
index 0a6a996..700e958 100644
--- a/src/asn1Coding.c
+++ b/src/asn1Coding.c
@@ -144,6 +144,7 @@ main (int argc, char *argv[])
unsigned char *der = NULL;
int der_len;
int k;
+ int last_ra;
set_program_name (argv[0]);
@@ -248,7 +249,8 @@ main (int argc, char *argv[])
putc ('\n', stderr);
- while (readAssignment (inputFile, varName, value) == ASSIGNMENT_SUCCESS)
+ while ((last_ra = readAssignment (inputFile, varName, value))
+ == ASSIGNMENT_SUCCESS)
{
fprintf (stderr, "var=%s, value=%s\n", varName, value);
if (structure == NULL)
@@ -273,6 +275,11 @@ main (int argc, char *argv[])
exit (1);
}
}
+ if (last_ra != ASSIGNMENT_EOF)
+ {
+ fprintf (stderr, "asn1Coding: error reading assignment file\n");
+ exit (1);
+ }
fclose (inputFile);
putc ('\n', stderr);