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