diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | README.md | 37 | ||||
-rw-r--r-- | configure.ac | 8 | ||||
-rwxr-xr-x | contrib/jenkins.sh | 4 | ||||
-rw-r--r-- | contrib/libasn1c.spec.in | 94 | ||||
-rw-r--r-- | debian/changelog | 58 | ||||
-rw-r--r-- | debian/compat | 2 | ||||
-rw-r--r-- | debian/control | 12 | ||||
-rw-r--r-- | include/asn1c/asn_internal.h | 26 | ||||
-rw-r--r-- | src/INTEGER.c | 10 | ||||
-rw-r--r-- | src/Makefile.am | 13 | ||||
-rw-r--r-- | src/constr_CHOICE.c | 4 | ||||
-rw-r--r-- | src/per_decoder.c | 2 |
13 files changed, 260 insertions, 13 deletions
@@ -8,6 +8,7 @@ autom4te.cache aclocal.m4 config.* configure +configure~ compile depcomp libtool @@ -21,3 +22,5 @@ libasn1c.pc *.la .deps .libs + +contrib/libasn1c.spec diff --git a/README.md b/README.md new file mode 100644 index 0000000..79d8491 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +libasn1c - shared library of asn1c runtime +========================================== + +This repository contains a shared library built from the asn1c runtime files. + +Normally, the upstream asn1c copies an identical set of source code files into each and every project using +asn1c. This becomes problematic if a single program uses multiple different ASN.1 specifications, where then +those source files would clash. + +Let's instead move those runtime files into a shared library (*libasn1c*), which is then linked once by each program +needing it, no matter how many asn1c-generated specifications/syntax it uses. + +**The version of the asn1c compiler must match the version of libasn1c**. We are using this shared library in +combination with the [osmocom fork of asn1c](https://gitea.osmocom.org/osmocom/asn1c). + + +GIT Repository +-------------- + +You can clone from the official libosmocore.git repository using + + git clone https://gitea.osmocom.org/cellular-infrastructure/libasn1c + +There is a web interface at <https://gitea.osmocom.org/cellular-infrastructure/libasn1c> + + +Mailing List +------------ + +Discussions related to libasn1c are happening on the +openbsc@lists.osmocom.org mailing list, please see +<https://lists.osmocom.org/mailman/listinfo/openbsc> for subscription +options and the list archive. + +Please observe the [Osmocom Mailing List +Rules](https://osmocom.org/projects/cellular-infrastructure/wiki/Mailing_List_Rules) +when posting. diff --git a/configure.ac b/configure.ac index 53720b9..6ba1d37 100644 --- a/configure.ac +++ b/configure.ac @@ -20,6 +20,11 @@ AC_PROG_LIBTOOL AC_CONFIG_MACRO_DIR([m4]) +dnl patching ${archive_cmds} to affect generation of file "libtool" to fix linking with clang +AS_CASE(["$LD"],[*clang*], + [AS_CASE(["${host_os}"], + [*linux*],[archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib'])]) + PKG_CHECK_MODULES(LIBTALLOC, talloc) AC_ARG_ENABLE(sanitize, @@ -75,4 +80,5 @@ AC_OUTPUT( src/Makefile include/Makefile include/asn1c/Makefile - Makefile) + Makefile + contrib/libasn1c.spec) diff --git a/contrib/jenkins.sh b/contrib/jenkins.sh index c23bdec..20314e5 100755 --- a/contrib/jenkins.sh +++ b/contrib/jenkins.sh @@ -15,8 +15,8 @@ set -x autoreconf --install --force ./configure --enable-werror $MAKE $PARALLEL_MAKE -$MAKE distcheck \ +$MAKE $PARALLEL_MAKE distcheck \ || cat-testlogs.sh -$MAKE maintainer-clean +$MAKE $PARALLEL_MAKE maintainer-clean osmo-clean-workspace.sh diff --git a/contrib/libasn1c.spec.in b/contrib/libasn1c.spec.in new file mode 100644 index 0000000..59098c3 --- /dev/null +++ b/contrib/libasn1c.spec.in @@ -0,0 +1,94 @@ +# +# spec file for package libasn1c +# +# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +Name: libasn1c +Version: @VERSION@ +Release: 0 +Summary: Osmocon ASN.1 decoder and encoder library +License: BSD-2-Clause +Group: Development/Libraries/C and C++ +Url: http://openbsc.osmocom.org/trac/ + +Source: %name-%version.tar.xz +BuildRequires: libtool >= 2 +BuildRequires: pkg-config +BuildRequires: xz +BuildRequires: pkgconfig(libosmocore) >= 0.1.13 +BuildRoot: %{_tmppath}/%{name}-%{version}-build + +%description +Lev Walkins's asn1c runtime, as a shared library and with +modifications for Osmocom. + +Compiles ASN.1 data structures into C source structures that can be +simply (un)marshalled from and to: BER, DER, CER, BASIC-XER, CXER, +EXTENDED-XER, PER. + +%package -n libasn1c1 +Summary: Osmocon ASN.1 decoder and encoder library +Group: System/Libraries + +%description -n libasn1c1 +Lev Walkins's asn1c runtime, as a shared library and with +modifications for Osmocom. + +Compiles ASN.1 data structures into C source structures that can be +simply (un)marshalled from and to: BER, DER, CER, BASIC-XER, CXER, +EXTENDED-XER, PER. + +%package -n libasn1c-devel +Summary: Development files for libasn1c, Osmocom's ASN.1 decoder and encoder library +Group: Development/Libraries/C and C++ +Requires: libasn1c1 = %version +Requires: libtalloc-devel + +%description -n libasn1c-devel +Compiles ASN.1 data structures into C source structures that can be +simply (un)marshalled from and to: BER, DER, CER, BASIC-XER, CXER, +EXTENDED-XER, PER. + +This subpackage contains libraries and header files for developing +applications that want to make use of libasn1c. + +%prep +%setup -q + +%build +echo "%{version}" >.tarball-version +autoreconf -fi +%configure --disable-static +make %{?_smp_mflags} + +%install +%make_install +find "%buildroot/%_libdir" -type f -name "*.la" -delete + +%check +make %{?_smp_mflags} check || (find . -name testsuite.log -exec cat {} +) + +%post -n libasn1c1 -p /sbin/ldconfig +%postun -n libasn1c1 -p /sbin/ldconfig + +%files -n libasn1c1 +%defattr(-,root,root) +%_libdir/libasn1c.so.1* + +%files -n libasn1c-devel +%defattr(-,root,root) +%doc COPYING +%_includedir/asn1c/ +%_libdir/pkgconfig/*.pc +%_libdir/libasn1c.so + +%changelog diff --git a/debian/changelog b/debian/changelog index e7480c2..447d441 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,61 @@ +libasn1c (0.9.36) unstable; urgency=medium + + [ Oliver Smith ] + * debian/control: replace, conflict: osmo-libasn1c + * INTEGER: ignore invalid -Warray-bounds from GCC-10 + * debian: set compat level to 10 + * INTEGER: ignore warning for all GCC versions + + [ Vadim Yanitskiy ] + * src/Makefile.am: libraries shall not be in LDFLAGS but in LIBADD + + [ Pau Espin Pedrol ] + * .gitignore: Add configure~ + * Disable _ASN_STACK_OVERFLOW_CHECK if building with Asan enabled + + -- Pau Espin Pedrol <pespin@sysmocom.de> Tue, 12 Sep 2023 12:34:28 +0200 + +libasn1c (0.9.35) unstable; urgency=medium + + [ Neels Hofmeyr ] + * fix 3 indents to avoid build failure with -Werror + + -- Pau Espin Pedrol <pespin@sysmocom.de> Tue, 07 Feb 2023 14:09:40 +0100 + +libasn1c (0.9.34) unstable; urgency=medium + + [ Eric ] + * configure.ac: fix libtool issue with clang and sanitizer + + -- Pau Espin Pedrol <pespin@sysmocom.de> Tue, 28 Jun 2022 16:03:31 +0200 + +libasn1c (0.9.33) unstable; urgency=medium + + [ Oliver Smith ] + * contrib: import RPM spec + * contrib: integrate RPM spec + + [ Vadim Yanitskiy ] + * debian/control: change maintainer to the Osmocom team / mailing list + + [ Pau Espin Pedrol ] + * contrib/jenkins: Enable parallel make in make distcheck + + -- Pau Espin Pedrol <pespin@sysmocom.de> Tue, 23 Feb 2021 16:52:29 +0100 + +libasn1c (0.9.32) unstable; urgency=medium + + [ Pau Espin Pedrol ] + * debian/rules: Don't overwrite .tarball-version + * Fix LIBVERSION not applied + + [ Oliver Smith ] + * jenkins.sh: disable parallel build + * Revert "jenkins.sh: disable parallel build" + * contrib/jenkins.sh: run "make maintainer-clean" + + -- Pau Espin Pedrol <pespin@sysmocom.de> Wed, 07 Aug 2019 13:26:10 +0200 + libasn1c (0.9.31) unstable; urgency=medium [ Alexander Couzens ] diff --git a/debian/compat b/debian/compat index ec63514..f599e28 100644 --- a/debian/compat +++ b/debian/compat @@ -1 +1 @@ -9 +10 diff --git a/debian/control b/debian/control index 32b93e3..49cac89 100644 --- a/debian/control +++ b/debian/control @@ -1,8 +1,10 @@ Source: libasn1c +Conflicts: osmo-libasn1c +Replaces: osmo-libasn1c Section: libs Priority: extra -Maintainer: Alexander Couzens <lynxis@fe80.eu> -Build-Depends: debhelper (>=9), +Maintainer: Osmocom team <openbsc@lists.osmocom.org> +Build-Depends: debhelper (>= 10), dh-autoreconf, libtalloc-dev Standards-Version: 3.9.8 @@ -11,6 +13,8 @@ Vcs-Browser: http://git.osmocom.org/gitweb?p=libasn1c.git;a=summary Homepage: https://projects.osmocom.org/projects/libasn1c Package: libasn1c1 +Conflicts: osmo-libasn1c1 +Replaces: osmo-libasn1c1 Section: libs Architecture: any Multi-Arch: same @@ -19,6 +23,8 @@ Depends: ${misc:Depends}, ${shlibs:Depends} Description: asn1c runtime code as shared library Package: libasn1c-dbg +Conflicts: osmo-libasn1c-dbg +Replaces: osmo-libasn1c-dbg Section: debug Architecture: any Multi-Arch: same @@ -26,6 +32,8 @@ Depends: libasn1c1 (= ${binary:Version}), ${misc:Depends} Description: asn1c runtime code as shared library Package: libasn1c-dev +Conflicts: osmo-libasn1c-dev +Replaces: osmo-libasn1c-dev Section: libdevel Architecture: any Multi-Arch: same diff --git a/include/asn1c/asn_internal.h b/include/asn1c/asn_internal.h index 580c2e7..0af6bd9 100644 --- a/include/asn1c/asn_internal.h +++ b/include/asn1c/asn_internal.h @@ -108,9 +108,34 @@ static inline void ASN_DEBUG(const char *fmt, ...) { (void)fmt; } /* * Check stack against overflow, if limit is set. */ + +/* Since GCC 13, AddressSanitizer started defaulting to +* ASAN_OPTIONS="detect_stack_use_after_return=1", which makes this check +* fail due to apparently jumping stack pointers. +* Hence, disable this check if building with ASan, as documented in: +* GCC: https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html +* Clang: https://clang.llvm.org/docs/AddressSanitizer.html#conditional-compilation-with-has-feature-address-sanitizer +*/ +#if defined(__SANITIZE_ADDRESS__) + #define _ASN_SANITIZE_ENABLED 1 +#elif defined(__has_feature) +#if __has_feature(address_sanitizer) + #define _ASN_SANITIZE_ENABLED 1 +#endif +#endif + #define _ASN_DEFAULT_STACK_MAX (30000) + +#if defined(_ASN_SANITIZE_ENABLED) static inline int _ASN_STACK_OVERFLOW_CHECK(asn_codec_ctx_t *ctx) { + (void)ctx; + return 0; +} +#else +static inline int +_ASN_STACK_OVERFLOW_CHECK(asn_codec_ctx_t *ctx) { + if(ctx && ctx->max_stack_size) { /* ctx MUST be allocated on the stack */ @@ -126,6 +151,7 @@ _ASN_STACK_OVERFLOW_CHECK(asn_codec_ctx_t *ctx) { } return 0; } +#endif #ifdef __cplusplus } diff --git a/src/INTEGER.c b/src/INTEGER.c index b3f0da1..1e62b2c 100644 --- a/src/INTEGER.c +++ b/src/INTEGER.c @@ -775,8 +775,8 @@ INTEGER_decode_aper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, ? asn_ulong2INTEGER(st, value) : asn_long2INTEGER(st, value)) _ASN_DECODE_FAILED; - ASN_DEBUG("Got value %ld + low %lld", - value, ct->lower_bound); + ASN_DEBUG("Got value %ld + low %lld", + value, ct->lower_bound); } return rval; } else { @@ -1336,9 +1336,12 @@ asn_int642INTEGER(INTEGER_t *st, int64_t value) { } break; } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" /* Copy the integer body */ for(pstart = p, bp = buf, pend1 += add; p != pend1; p += add) *bp++ = *p; +#pragma GCC diagnostic pop if(st->buf) FREEMEM(st->buf); st->buf = buf; @@ -1391,9 +1394,12 @@ asn_long2INTEGER(INTEGER_t *st, long value) { } break; } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" /* Copy the integer body */ for(pstart = p, bp = buf, pend1 += add; p != pend1; p += add) *bp++ = *p; +#pragma GCC diagnostic pop if(st->buf) FREEMEM(st->buf); st->buf = buf; diff --git a/src/Makefile.am b/src/Makefile.am index 29b5e64..5e9a0d7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,7 @@ # This is _NOT_ the library release version, it's an API version. # Please read Chapter 6 "Library interface versions" of the libtool # documentation before making any modification -LIBVERSION=1:1:0 +LIBVERSION=1:2:0 AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include/asn1c AM_CFLAGS = -fPIC -Wall $(LIBTALLOC_CFLAGS) @@ -11,5 +11,14 @@ endif lib_LTLIBRARIES = libasn1c.la -libasn1c_la_LDFLAGS = $(LIBTALLOC_LIBS) -lm -version-info $(LIBVERSION) -no-undefined +libasn1c_la_LIBADD = \ + $(LIBTALLOC_LIBS) \ + -lm \ + $(NULL) + +libasn1c_la_LDFLAGS = \ + -version-info $(LIBVERSION) \ + -no-undefined \ + $(NULL) + libasn1c_la_SOURCES = ANY.c constraints.c GeneralizedTime.c NumericString.c T61String.c asn_codecs_prim.c constr_CHOICE.c GeneralString.c ObjectDescriptor.c TeletexString.c asn_SEQUENCE_OF.c constr_SEQUENCE.c GraphicString.c OBJECT_IDENTIFIER.c UniversalString.c asn_SET_OF.c constr_SEQUENCE_OF.c IA5String.c OCTET_STRING.c UTCTime.c ber_decoder.c constr_SET.c INTEGER.c per_decoder.c UTF8String.c ber_tlv_length.c constr_SET_OF.c ISO646String.c per_encoder.c VideotexString.c ber_tlv_tag.c constr_TYPE.c NativeEnumerated.c per_support.c VisibleString.c BIT_STRING.c NativeInteger.c PrintableString.c xer_decoder.c BMPString.c der_encoder.c NativeReal.c REAL.c xer_encoder.c BOOLEAN.c ENUMERATED.c NULL.c RELATIVE-OID.c xer_support.c per_opentype.c asn1helpers.c diff --git a/src/constr_CHOICE.c b/src/constr_CHOICE.c index 18c24cd..df68feb 100644 --- a/src/constr_CHOICE.c +++ b/src/constr_CHOICE.c @@ -1134,8 +1134,8 @@ CHOICE_encode_aper(asn_TYPE_descriptor_t *td, if(per_put_few_bits(po, present, ct->range_bits)) _ASN_ENCODE_FAILED; - return elm->type->aper_encoder(elm->type, elm->per_constraints, - memb_ptr, po); + return elm->type->aper_encoder(elm->type, elm->per_constraints, + memb_ptr, po); } else { asn_enc_rval_t rval; if(specs->ext_start == -1) diff --git a/src/per_decoder.c b/src/per_decoder.c index 20fe1a1..b5056b5 100644 --- a/src/per_decoder.c +++ b/src/per_decoder.c @@ -160,7 +160,7 @@ aper_decode(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, void **sp */ if(!td->aper_decoder) _ASN_DECODE_FAILED; /* PER is not compiled in */ - rval = td->aper_decoder(opt_codec_ctx, td, 0, sptr, &pd); + rval = td->aper_decoder(opt_codec_ctx, td, 0, sptr, &pd); if(rval.code == RC_OK) { /* Return the number of consumed bits */ rval.consumed = ((pd.buffer - (const uint8_t *)buffer) << 3) |