diff --git a/.gitignore b/.gitignore index c161967..265e82e 100644 --- a/.gitignore +++ b/.gitignore @@ -203,5 +203,6 @@ /tests/setof /tests/spc_pe_image_data /tests/strict-der +/tests/version /windows/libtasn1-*-win??.zip /windows/tmp diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 441c545..649a9a5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -290,6 +290,7 @@ Alpine: - tar xfa libtasn1-*.tar.gz - cd `ls -d libtasn1-* | grep -v tar.gz` - ./configure --enable-gcc-warnings || (cat config.log; exit 1) + - sed -i 's/UNKNOWN/10.11.12/g' tests/version.c # XXX FIXME alpine bug? - make check V=1 || (find . -name test-suite.log -exec cat {} +; exit 1) ArchLinux: diff --git a/tests/Makefile.am b/tests/Makefile.am index b3c69c5..8347514 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -64,7 +64,7 @@ ctests = Test_parser Test_tree Test_encoding Test_indefinite \ Test_choice Test_encdec copynode coding-decoding2 strict-der \ Test_choice_ocsp ocsp-basic-response octet-string \ coding-long-oid object-id-decoding spc_pe_image_data setof \ - CVE-2018-1000654 reproducers object-id-encoding + CVE-2018-1000654 reproducers object-id-encoding version check_PROGRAMS = $(ctests) TESTS = $(ctests) crlf.sh threadsafety.sh decoding.sh \ diff --git a/tests/reproducers.c b/tests/reproducers.c index 9f54afb..a09d8b0 100644 --- a/tests/reproducers.c +++ b/tests/reproducers.c @@ -58,62 +58,6 @@ main (int argc, char *argv[]) int result, verbose = 0; asn1_node definitions = NULL; char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; - char *out = errorDescription; - int i; - - printf ("Header version %s library version %s\n", - ASN1_VERSION, asn1_check_version (NULL)); - - if (!asn1_check_version (ASN1_VERSION)) - { - printf ("asn1_check_version failure\n"); - exit (EXIT_FAILURE); - } - - if (!asn1_check_version ("4.17.0")) - { - printf ("asn1_check_version(4.17.0) failure\n"); - exit (EXIT_FAILURE); - } - - if (!asn1_check_version ("4.17")) - { - printf ("asn1_check_version(4.17) failure\n"); - exit (EXIT_FAILURE); - } - - if (strcmp (ASN1_VERSION, asn1_check_version (NULL)) != 0) - { - printf ("header version mismatch library version\n"); - exit (EXIT_FAILURE); - } - - i = ASN1_VERSION_MAJOR * 256 * 256 + - ASN1_VERSION_MINOR * 256 + ASN1_VERSION_PATCH; - - snprintf (out, ASN1_MAX_ERROR_DESCRIPTION_SIZE - 1, "%d.%d.%d", - ASN1_VERSION_MAJOR, ASN1_VERSION_MINOR, ASN1_VERSION_PATCH); - - printf ("Header version %s number %x derived %x\n", out, - (unsigned) ASN1_VERSION_NUMBER, (unsigned) i); - - if (ASN1_VERSION_NUMBER != i) - { - printf ("header version number mismatch\n"); - exit (EXIT_FAILURE); - } - - if (!asn1_check_version (out)) - { - printf ("asn1_check_version(%s) failure\n", out); - exit (EXIT_FAILURE); - } - - if (strncmp (ASN1_VERSION, out, strlen (out)) != 0) - { - printf ("header version numbers mismatch library version\n"); - exit (EXIT_FAILURE); - } if (argc > 1) verbose = 1; diff --git a/tests/version.c b/tests/version.c new file mode 100644 index 0000000..15c4919 --- /dev/null +++ b/tests/version.c @@ -0,0 +1,122 @@ +/* version.c --- Version handling self tests. + * Copyright (C) 2019-2022 Free Software Foundation, Inc. + * + * This file is part of LIBTASN1. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include /* printf */ +#include /* EXIT_SUCCESS */ +#include /* strcmp */ + +/* Get ASN1 prototypes. */ +#include + +int +main (int argc, char *argv[]) +{ + int exit_code = EXIT_SUCCESS; + char out[100]; + int j; + unsigned gvn = ASN1_VERSION_NUMBER; + unsigned gvmmp = (ASN1_VERSION_MAJOR << 16) + + (ASN1_VERSION_MINOR << 8) + ASN1_VERSION_PATCH; + + printf ("ASN1_VERSION: %s\n", ASN1_VERSION); + printf ("ASN1_VERSION_MAJOR: %d\n", ASN1_VERSION_MAJOR); + printf ("ASN1_VERSION_MINOR: %d\n", ASN1_VERSION_MINOR); + printf ("ASN1_VERSION_PATCH: %d\n", ASN1_VERSION_PATCH); + printf ("ASN1_VERSION_NUMBER: %x\n", gvn); + printf ("(ASN1_VERSION_MAJOR << 16) + (ASN1_VERSION_MINOR << 8)" + " + ASN1_VERSION_PATCH: %x\n", gvmmp); + + j = snprintf (out, sizeof (out) - 1, "%d.%d.%d", ASN1_VERSION_MAJOR, + ASN1_VERSION_MINOR, ASN1_VERSION_PATCH); + if (j < 0) + { + printf ("snprintf failure: %d", j); + exit_code = EXIT_FAILURE; + out[0] = '\0'; + } + + if (out[0]) + printf ("ASN1_VERSION_MAJOR.ASN1_VERSION_MINOR.ASN1_VERSION_PATCH: %s\n", + out); + + printf ("asn1_check_version (NULL): %s\n", asn1_check_version (NULL)); + + if (!asn1_check_version (ASN1_VERSION)) + { + printf ("FAIL: asn1_check_version (ASN1_VERSION)\n"); + exit_code = EXIT_FAILURE; + } + + if (!asn1_check_version ("4.17.0")) + { + printf ("asn1_check_version(4.17.0) failure\n"); + exit_code = EXIT_FAILURE; + } + + if (!asn1_check_version ("4.17")) + { + printf ("asn1_check_version(4.17) failure\n"); + exit_code = EXIT_FAILURE; + } + + if (strcmp (ASN1_VERSION, asn1_check_version (NULL)) != 0) + { + printf ("FAIL: strcmp (ASN1_VERSION, asn1_check_version (NULL))\n"); + exit_code = EXIT_FAILURE; + } + + if (ASN1_VERSION_NUMBER != gvn) + { + printf ("FAIL: ASN1_VERSION_NUMBER != gvn\n"); + exit_code = EXIT_FAILURE; + } + + if (out[0]) + { + if (!asn1_check_version (out)) + { + printf ("FAIL: asn1_check_version(%s)\n", out); + exit_code = EXIT_FAILURE; + } + + /* ASN1_VERSION may look like "1.0.4.10-b872" but the derived string + should be "1.0.4" anyway. */ + if (strncmp (ASN1_VERSION, out, strlen (out)) != 0) + { + printf ("FAIL: strncmp (ASN1_VERSION, %s, strlen (%s))\n", out, + out); + exit_code = EXIT_FAILURE; + } + } + + if (asn1_check_version ("4711.42.23")) + { + printf ("FAIL: asn1_check_version(4711.42.23)\n"); + exit_code = EXIT_FAILURE; + } + + if (asn1_check_version ("UNKNOWN")) + { + printf ("FAIL: asn1_check_version (UNKNOWN)\n"); + exit_code = EXIT_FAILURE; + } + + return exit_code; +}