aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2023-05-04 18:37:57 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2023-05-05 13:15:54 +0200
commit3e483e59502fac088198b486fc44c1a20dc73b50 (patch)
tree05e800ec1ed9d49df85e42f870ea8283481ccae8 /include
parent5cdcaffc15e481e4eb34b53132bc207fffea6219 (diff)
Disable _ASN_STACK_OVERFLOW_CHECK if building with Asan enabled
Diffstat (limited to 'include')
-rw-r--r--include/asn1c/asn_internal.h26
1 files changed, 26 insertions, 0 deletions
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
}