Commit d1c28aa8 authored by Lev Walkin's avatar Lev Walkin

generate OER and PER by default. add -no-gen-example

parent d5f6647f
......@@ -18,6 +18,8 @@
then ensure the new clang is in the way:
CC=clang CXX=clang++ ./configure --enable-Werror --enable-test-fuzzer
* uper_encode() API got new argument (breaks API compatibility).
* asn1c -gen-XXX flags are deprecated. Use -no-gen-XXX to disable codecs.
* asn1c -no-gen-example option to disable converter-example generation.
FIXES:
* CVE-2017-12966 verified not present.
......
......@@ -56,7 +56,8 @@ int
main(int ac, char **av) {
enum asn1p_flags asn1_parser_flags = A1P_NOFLAGS;
enum asn1f_flags asn1_fixer_flags = A1F_NOFLAGS;
enum asn1c_flags asn1_compiler_flags = A1C_NO_C99;
enum asn1c_flags asn1_compiler_flags =
A1C_NO_C99 | A1C_GEN_OER | A1C_GEN_PER | A1C_GEN_EXAMPLE;
enum asn1print_flags asn1_printer_flags = APF_NOFLAGS;
int print_arg__print_out = 0; /* Don't compile, just print parsed */
int print_arg__fix_n_print = 0; /* Fix and print */
......@@ -71,7 +72,7 @@ main(int ac, char **av) {
/*
* Process command-line options.
*/
while((ch = getopt(ac, av, "EFf:g:hLPp:RS:vW:X")) != -1) switch(ch) {
while((ch = getopt(ac, av, "EFf:g:hn:LPp:RS:vW:X")) != -1) switch(ch) {
case 'E':
print_arg__print_out = 1;
break;
......@@ -121,6 +122,8 @@ main(int ac, char **av) {
asn1_compiler_flags |= A1C_GEN_PER;
} else if(strcmp(optarg, "en-OER") == 0) {
asn1_compiler_flags |= A1C_GEN_OER;
} else if(strcmp(optarg, "en-example") == 0) {
asn1_compiler_flags |= A1C_GEN_EXAMPLE;
} else {
fprintf(stderr, "-g%s: Invalid argument\n", optarg);
exit(EX_USAGE);
......@@ -128,6 +131,18 @@ main(int ac, char **av) {
break;
case 'h':
usage(av[0]);
case 'n':
if(strcmp(optarg, "o-gen-PER") == 0) {
asn1_compiler_flags &= ~A1C_GEN_PER;
} else if(strcmp(optarg, "o-gen-OER") == 0) {
asn1_compiler_flags &= ~A1C_GEN_OER;
} else if(strcmp(optarg, "o-gen-example") == 0) {
asn1_compiler_flags &= ~A1C_GEN_EXAMPLE;
} else {
fprintf(stderr, "-n%s: Invalid argument\n", optarg);
exit(EX_USAGE);
}
break;
case 'P':
asn1_compiler_flags |= A1C_PRINT_COMPILED;
asn1_compiler_flags &= ~A1C_NO_C99;
......@@ -500,14 +515,15 @@ usage(const char *av0) {
" -fincludes-quoted Generate #includes in \"double\" instead of <angle> quotes\n"
" -fknown-extern-type=<name> Pretend the specified type is known\n"
" -fline-refs Include ASN.1 module's line numbers in comments\n"
" -fno-constraints Do not generate constraint checking code\n"
" -fno-include-deps Do not generate courtesy #includes for dependencies\n"
" -fno-constraints Do not generate the constraint checking code\n"
" -fno-include-deps Do not generate the courtesy #includes for dependencies\n"
" -funnamed-unions Enable unnamed unions in structures\n"
" -fwide-types Use INTEGER_t instead of \"long\" by default, etc.\n"
"\n"
" -gen-OER Generate OER (X.696) support code\n"
" -gen-PER Generate PER (X.691) support code\n"
" -no-gen-OER Do not generate the OER (X.696) support code\n"
" -no-gen-PER Do not generate the PER (X.691) support code\n"
" -no-gen-example Do not generate the ASN.1 format converter example\n"
" -pdu={all|auto|Type} Generate PDU table (discover PDUs automatically)\n"
"\n"
......
No preview for this file type
......@@ -142,7 +142,7 @@ END
\item Compile it into the set of .c and .h files using \cmd{asn1c} compiler:
\begin{bash}
asn1c -gen-OER -gen-PER %\textbf{rectangle.asn}%
asn1c -no-gen-example %\textbf{rectangle.asn}%
\end{bash}
\item Create the converter and dumper:
......@@ -178,7 +178,7 @@ END
\item Compile it into the set of .c and .h files using asn1c compiler \cite{ASN1C}:
\begin{bash}
asn1c %\textbf{rectangle.asn}%
asn1c -no-gen-example %\textbf{rectangle.asn}%
\end{bash}
\item Alternatively, use the Online ASN.1 compiler \cite{AONL} by uploading
the \textbf{rectangle.asn} file into the Web form and unpacking the
......@@ -275,7 +275,7 @@ END
\item Compile it into the set of .c and .h files using asn1c compiler \cite{ASN1C}:
\begin{bash}
asn1c %\textbf{rectangle.asn}%
asn1c -no-gen-example %\textbf{rectangle.asn}%
\end{bash}
\item Alternatively, use the Online ASN.1 compiler \cite{AONL} by uploading
the \textbf{rectangle.asn} file into the Web form and unpacking the
......@@ -484,7 +484,7 @@ after compilation will be rather small anyway.
\item A \textbf{Makefile.am.libasncodecs} file which explicitly lists all the
generated files.
This makefile can be used on its own to build the just the codec library.
\item A \textbf{converter-example.c} file containing the \emph{int main()} function with a fully functioning encoder and data format converter. It can convert a given PDU between BER, XER and possibly OER and PER (if \cmd{-gen-OER} or \cmd{-gen-PER} options to \cmd{asn1c} were in effect). At some point you will want to replace this file with your own file containing the \emph{int main()} function.
\item A \textbf{converter-example.c} file containing the \emph{int main()} function with a fully functioning encoder and data format converter. It can convert a given PDU between BER, XER, OER and PER. At some point you will want to replace this file with your own file containing the \emph{int main()} function.
\item A \textbf{Makefile.am.example} file which binds together
\textbf{Makefile.am.libasncodecs} and \textbf{converter-example.c}
to build a versatile converter and debugger for your data formats.
......@@ -545,15 +545,16 @@ to prevent circular references.}\\
the target language source files for the given type have been provided
manually. }\\
{\ttfamily -fline-refs} & {\small Include ASN.1 module's line numbers in generated code comments.}\\
{\ttfamily -fno-constraints} & {\small Do not generate ASN.1 subtype constraint checking code. This
{\ttfamily -fno-constraints} & {\small Do not generate the ASN.1 subtype constraint checking code. This
may produce a shorter executable.}\\
{\ttfamily -fno-include-deps} & {\small Do not generate courtesy \#include lines for non-critical dependencies.}\\
{\ttfamily -fno-include-deps} & {\small Do not generate the courtesy \#include lines for non-critical dependencies.}\\
{\ttfamily -funnamed-unions} & {\small Enable unnamed unions in the definitions of target language's structures.}\\
{\ttfamily -fwide-types} & {\small Use the wide integer types (INTEGER\_t, REAL\_t) instead of machine's native data types (long, double). }\\\\
\textbf{Codecs Generation Options} & \textbf{Description}\\
\midrule
{\ttfamily -gen-OER} & {\small Generate the Octet Encoding Rules (OER) support code.}\\
{\ttfamily -gen-PER} & {\small Generate the Packed Encoding Rules (PER) support code.}\\
{\ttfamily -no-gen-OER} & {\small Do not generate the Octet Encoding Rules (OER, X.696) support code.}\\
{\ttfamily -no-gen-PER} & {\small Do not generate the Packed Encoding Rules (PER, X.691) support code.}\\
{\ttfamily -no-gen-example} & {\small Do not generate the ASN.1 format converter example.}\\
{\ttfamily -pdu=\{\textbf{all}|\textbf{auto}|\emph{Type}\}} & {\small Create a PDU table for specified types, or discover the Protocol Data Units automatically.
In case of \texttt{-pdu=\textbf{all}}, all ASN.1 types defined in all modules wil form a PDU table. In case of \texttt{-pdu=\textbf{auto}}, all types not referenced by any other type will form a PDU table. If \texttt{\emph{Type}} is an ASN.1 type identifier, it is added to a PDU table. The last form may be specified multiple times.}\\ \\
\textbf{Output Options} & \textbf{Description}\\
......@@ -841,9 +842,10 @@ int asn_random_fill(
Create or initialize a structure with random contents, according to the type
specification and optional member constraints.
For best results, the code should be generated with \cmd{-gen-PER} option
to \cmd{asn1c}, that will make it follow the PER visible constraints and
sometimes break out of extensible contstraints' ranges.
For best results the code should be generated without \cmd{-no-gen-PER}
option to \cmd{asn1c}. Making PER constraints code available in runtime
will make \code{asn_random_fill} explore the edges of PER-visible constraints
and sometimes break out of extensible contstraints' ranges.
The \code{asn_random_fill()} function has a bias to generate edge case
values. This property makes it useful for debugging the application level
......
......@@ -109,7 +109,11 @@ asn1c__save_library_makefile(arg_t *arg, const asn1c_fdeps_t *deps, const char *
assert(strlen(fname) < (sizeof(buf) / 2));
strcpy(dir_end, fname);
if(asn1c_copy_over(arg, buf) == -1) {
if(dlist->elements[i]->usage == FDEP_CONVERTER
&& !(arg->flags & A1C_GEN_EXAMPLE))
continue;
if(asn1c_copy_over(arg, buf) == -1) {
safe_fprintf(mkf, ">>>ABORTED<<<");
fclose(mkf);
return -1;
......@@ -156,7 +160,6 @@ asn1c__save_example_makefile(arg_t *arg, const asn1c_fdeps_t *deps,
const char *makefile_name,
const char *library_makefile_name, int argc,
char **argv) {
asn1c_fdeps_t *dlist;
FILE *mkf;
mkf = asn1c_open_file(makefile_name, "", 0);
......@@ -176,16 +179,18 @@ asn1c__save_example_makefile(arg_t *arg, const asn1c_fdeps_t *deps,
(arg->flags & A1C_PDU_TYPE) ? generate_pdu_C_definition() : "",
need_to_generate_pdu_collection(arg) ? "-DASN_PDU_COLLECTION " : "");
dlist = asn1c_deps_flatten(deps);
if(dlist) {
/* only CONVERTER data in the makefile */
for(int i = 0; i < dlist->el_count; i++) {
if(dlist->elements[i]->usage == FDEP_CONVERTER) {
safe_fprintf(mkf, "\\\n\t%s", dlist->elements[i]->filename);
}
}
asn1c_deps_freelist(dlist);
}
if(arg->flags & A1C_GEN_EXAMPLE) {
asn1c_fdeps_t *dlist = asn1c_deps_flatten(deps);
if(dlist) {
/* only CONVERTER data in the makefile */
for(int i = 0; i < dlist->el_count; i++) {
if(dlist->elements[i]->usage == FDEP_CONVERTER) {
safe_fprintf(mkf, "\\\n\t%s", dlist->elements[i]->filename);
}
}
asn1c_deps_freelist(dlist);
}
}
if(need_to_generate_pdu_collection(arg)) {
safe_fprintf(mkf, "\\\n\tpdu_collection.c");
......@@ -274,9 +279,13 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir,
ret = asn1c__save_library_makefile(arg, deps, datadir,
"Makefile.am.libasncodec");
if(ret) break;
ret = asn1c__save_example_makefile(arg, deps, "Makefile.am.example",
"Makefile.am.libasncodec", argc, argv);
if(ret) break;
if(arg->flags & A1C_GEN_EXAMPLE) {
ret = asn1c__save_example_makefile(arg, deps, "Makefile.am.example",
"Makefile.am.libasncodec", argc,
argv);
if(ret) break;
}
} while(0);
asn1c_deps_freelist(deps);
......
......@@ -84,6 +84,10 @@ enum asn1c_flags {
* Generate Packed Encoding Rules support code
*/
A1C_GEN_PER = 0x80000,
/*
* Generate converter-example.c and Makefile.am.example
*/
A1C_GEN_EXAMPLE = 0x100000,
};
/*
......
......@@ -31,13 +31,13 @@ for ref in ${top_srcdir}/tests/tests-asn1c-compiler/*.asn1.-*; do
newversion=${template}.new
PROCESSING="$ref (from $src)"
LANG=C sed -e 's/^found in .*/found in .../' < "$ref" > "$oldversion"
(${top_builddir}/asn1c/asn1c -S ${top_srcdir}/skeletons "-$flags" "$src" | LANG=C sed -e 's/^found in .*/found in .../' > "$newversion") || ec=$?
(${top_builddir}/asn1c/asn1c -S ${top_srcdir}/skeletons -no-gen-OER -no-gen-PER "-$flags" "$src" | LANG=C sed -e 's/^found in .*/found in .../' > "$newversion") || ec=$?
if [ $? = 0 ]; then
diff $diffArgs "$oldversion" "$newversion" || ec=$?
fi
rm -f $oldversion $newversion
if [ "$1" = "regenerate" ]; then
${top_builddir}/asn1c/asn1c -S ${top_srcdir}/skeletons "-$flags" "$src" > "$ref"
${top_builddir}/asn1c/asn1c -S ${top_srcdir}/skeletons -no-gen-OER -no-gen-PER "-$flags" "$src" > "$ref"
fi
done
......
......@@ -254,7 +254,7 @@ asn1c_invoke() {
} > ${tmpfile}
echo "${abs_top_builddir}/asn1c/asn1c -S ${abs_top_srcdir}/skeletons"
if "${abs_top_builddir}/asn1c/asn1c" -S "${abs_top_srcdir}/skeletons" \
-gen-OER -gen-PER ${asn1c_flags} $@ ${tmpfile}
${asn1c_flags} $@ ${tmpfile}
then
echo "ASN.1 compiled OK"
else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment