From: Alberto Leiva Popper Date: Fri, 30 Jun 2023 17:51:44 +0000 (-0600) Subject: Update asn1c for its generated code X-Git-Tag: 1.6.0~79^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dc6394fa11bdbff9a593be41cc05d7f8db10fbff;p=thirdparty%2FFORT-validator.git Update asn1c for its generated code Inherits miscellaneous bugfixes. Bumps asn1c from version 88ed3b5cf012918bc1084b606b0624c45e0d2191 to 9925dbbda86b436896108439ea3e0a31280a6065. --- diff --git a/src/asn1/asn1c/INTEGER.c b/src/asn1/asn1c/INTEGER.c index 919ef7d1..3ac4efc1 100644 --- a/src/asn1/asn1c/INTEGER.c +++ b/src/asn1/asn1c/INTEGER.c @@ -1,5 +1,5 @@ -/*- - * Copyright (c) 2003-2014 Lev Walkin . +/* + * Copyright (c) 2003-2019 Lev Walkin . * All rights reserved. * Redistribution and modifications are permitted subject to BSD license. */ @@ -1037,64 +1037,71 @@ asn_ulong2INTEGER(INTEGER_t *st, unsigned long value) { */ enum asn_strtox_result_e asn_strtoimax_lim(const char *str, const char **end, intmax_t *intp) { - int sign = 1; - intmax_t value; + int sign = 1; + intmax_t value; -#define ASN1_INTMAX_MAX ((~(uintmax_t)0) >> 1) - const intmax_t upper_boundary = ASN1_INTMAX_MAX / 10; - intmax_t last_digit_max = ASN1_INTMAX_MAX % 10; -#undef ASN1_INTMAX_MAX + const intmax_t asn1_intmax_max = ((~(uintmax_t)0) >> 1); + const intmax_t upper_boundary = asn1_intmax_max / 10; + intmax_t last_digit_max = asn1_intmax_max % 10; - if(str >= *end) return ASN_STRTOX_ERROR_INVAL; + if(str >= *end) return ASN_STRTOX_ERROR_INVAL; - switch(*str) { - case '-': - last_digit_max++; - sign = -1; - /* FALL THROUGH */ - case '+': - str++; - if(str >= *end) { - *end = str; - return ASN_STRTOX_EXPECT_MORE; - } - } + switch(*str) { + case '-': + last_digit_max++; + sign = -1; + /* FALL THROUGH */ + case '+': + str++; + if(str >= *end) { + *end = str; + return ASN_STRTOX_EXPECT_MORE; + } + } - for(value = 0; str < (*end); str++) { - switch(*str) { - case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: - case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: { - int d = *str - '0'; - if(value < upper_boundary) { - value = value * 10 + d; - } else if(value == upper_boundary) { - if(d <= last_digit_max) { - if(sign > 0) { - value = value * 10 + d; - } else { - sign = 1; - value = -value * 10 - d; - } - } else { - *end = str; - return ASN_STRTOX_ERROR_RANGE; - } - } else { - *end = str; - return ASN_STRTOX_ERROR_RANGE; - } - } - continue; - default: - *end = str; - *intp = sign * value; - return ASN_STRTOX_EXTRA_DATA; - } - } + for(value = 0; str < (*end); str++) { + if(*str >= 0x30 && *str <= 0x39) { + int d = *str - '0'; + if(value < upper_boundary) { + value = value * 10 + d; + } else if(value == upper_boundary) { + if(d <= last_digit_max) { + if(sign > 0) { + value = value * 10 + d; + } else { + sign = 1; + value = -value * 10 - d; + } + str += 1; + if(str < *end) { + // If digits continue, we're guaranteed out of range. + *end = str; + if(*str >= 0x30 && *str <= 0x39) { + return ASN_STRTOX_ERROR_RANGE; + } else { + *intp = sign * value; + return ASN_STRTOX_EXTRA_DATA; + } + } + break; + } else { + *end = str; + return ASN_STRTOX_ERROR_RANGE; + } + } else { + *end = str; + return ASN_STRTOX_ERROR_RANGE; + } + } else { + *end = str; + *intp = sign * value; + return ASN_STRTOX_EXTRA_DATA; + } + } - *end = str; - *intp = sign * value; - return ASN_STRTOX_OK; + *end = str; + *intp = sign * value; + return ASN_STRTOX_OK; } /* @@ -1105,56 +1112,63 @@ asn_strtoimax_lim(const char *str, const char **end, intmax_t *intp) { */ enum asn_strtox_result_e asn_strtoumax_lim(const char *str, const char **end, uintmax_t *uintp) { - uintmax_t value; + uintmax_t value; -#define ASN1_UINTMAX_MAX ((~(uintmax_t)0)) - const uintmax_t upper_boundary = ASN1_UINTMAX_MAX / 10; - uintmax_t last_digit_max = ASN1_UINTMAX_MAX % 10; -#undef ASN1_UINTMAX_MAX + const uintmax_t asn1_uintmax_max = ((~(uintmax_t)0)); + const uintmax_t upper_boundary = asn1_uintmax_max / 10; + uintmax_t last_digit_max = asn1_uintmax_max % 10; if(str >= *end) return ASN_STRTOX_ERROR_INVAL; - switch(*str) { - case '-': + switch(*str) { + case '-': return ASN_STRTOX_ERROR_INVAL; - case '+': - str++; - if(str >= *end) { - *end = str; - return ASN_STRTOX_EXPECT_MORE; - } - } + case '+': + str++; + if(str >= *end) { + *end = str; + return ASN_STRTOX_EXPECT_MORE; + } + } - for(value = 0; str < (*end); str++) { - switch(*str) { - case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: - case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: { - unsigned int d = *str - '0'; - if(value < upper_boundary) { - value = value * 10 + d; - } else if(value == upper_boundary) { - if(d <= last_digit_max) { + for(value = 0; str < (*end); str++) { + if(*str >= 0x30 && *str <= 0x39) { + unsigned int d = *str - '0'; + if(value < upper_boundary) { + value = value * 10 + d; + } else if(value == upper_boundary) { + if(d <= last_digit_max) { value = value * 10 + d; + str += 1; + if(str < *end) { + // If digits continue, we're guaranteed out of range. + *end = str; + if(*str >= 0x30 && *str <= 0x39) { + return ASN_STRTOX_ERROR_RANGE; + } else { + *uintp = value; + return ASN_STRTOX_EXTRA_DATA; + } + } + break; } else { - *end = str; - return ASN_STRTOX_ERROR_RANGE; - } - } else { - *end = str; - return ASN_STRTOX_ERROR_RANGE; - } - } - continue; - default: - *end = str; - *uintp = value; - return ASN_STRTOX_EXTRA_DATA; - } - } + *end = str; + return ASN_STRTOX_ERROR_RANGE; + } + } else { + *end = str; + return ASN_STRTOX_ERROR_RANGE; + } + } else { + *end = str; + *uintp = value; + return ASN_STRTOX_EXTRA_DATA; + } + } - *end = str; - *uintp = value; - return ASN_STRTOX_OK; + *end = str; + *uintp = value; + return ASN_STRTOX_OK; } enum asn_strtox_result_e diff --git a/src/asn1/asn1c/LICENSE b/src/asn1/asn1c/LICENSE index 5e5b6ad0..7075dbf1 100644 --- a/src/asn1/asn1c/LICENSE +++ b/src/asn1/asn1c/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2003-2013 Lev Walkin +Copyright (c) 2003-2017 Lev Walkin and contributors. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/src/asn1/asn1c/NULL.c b/src/asn1/asn1c/NULL.c index 50997268..80ed7231 100644 --- a/src/asn1/asn1c/NULL.c +++ b/src/asn1/asn1c/NULL.c @@ -5,7 +5,6 @@ #include "asn1/asn1c/asn_internal.h" #include "asn1/asn1c/asn_codecs_prim.h" #include "asn1/asn1c/NULL.h" -#include "asn1/asn1c/BOOLEAN.h" /* Implemented in terms of BOOLEAN type */ /* * NULL basic type description. @@ -14,10 +13,10 @@ static const ber_tlv_tag_t asn_DEF_NULL_tags[] = { (ASN_TAG_CLASS_UNIVERSAL | (5 << 2)) }; asn_TYPE_operation_t asn_OP_NULL = { - BOOLEAN_free, + NULL_free, NULL_print, NULL_compare, - BOOLEAN_decode_ber, /* Implemented in terms of BOOLEAN */ + NULL_decode_ber, NULL_encode_der, /* Special handling of DER encoding */ NULL_decode_xer, NULL_encode_xer, @@ -51,6 +50,65 @@ asn_TYPE_descriptor_t asn_DEF_NULL = { 0 /* No specifics */ }; +void +NULL_free(const asn_TYPE_descriptor_t *td, void *ptr, + enum asn_struct_free_method method) { + if(td && ptr) { + switch(method) { + case ASFM_FREE_EVERYTHING: + FREEMEM(ptr); + break; + case ASFM_FREE_UNDERLYING: + break; + case ASFM_FREE_UNDERLYING_AND_RESET: + memset(ptr, 0, sizeof(NULL_t)); + break; + } + } +} + +/* + * Decode NULL type. + */ +asn_dec_rval_t +NULL_decode_ber(const asn_codec_ctx_t *opt_codec_ctx, + const asn_TYPE_descriptor_t *td, void **bool_value, + const void *buf_ptr, size_t size, int tag_mode) { + NULL_t *st = (NULL_t *)*bool_value; + asn_dec_rval_t rval; + ber_tlv_len_t length; + + if(st == NULL) { + st = (NULL_t *)(*bool_value = CALLOC(1, sizeof(*st))); + if(st == NULL) { + rval.code = RC_FAIL; + rval.consumed = 0; + return rval; + } + } + + ASN_DEBUG("Decoding %s as NULL (tm=%d)", td->name, tag_mode); + + /* + * Check tags. + */ + rval = ber_check_tags(opt_codec_ctx, td, 0, buf_ptr, size, tag_mode, 0, + &length, 0); + if(rval.code != RC_OK) { + return rval; + } + + // X.690-201508, #8.8.2, length shall be zero. + if(length != 0) { + ASN_DEBUG("Decoding %s as NULL failed: too much data", td->name); + rval.code = RC_FAIL; + rval.consumed = 0; + return rval; + } + + return rval; +} + asn_enc_rval_t NULL_encode_der(const asn_TYPE_descriptor_t *td, const void *ptr, int tag_mode, ber_tlv_tag_t tag, asn_app_consume_bytes_f *cb, void *app_key) { diff --git a/src/asn1/asn1c/NULL.h b/src/asn1/asn1c/NULL.h index 1c3f787d..6153e2d4 100644 --- a/src/asn1/asn1c/NULL.h +++ b/src/asn1/asn1c/NULL.h @@ -6,23 +6,24 @@ #define ASN_TYPE_NULL_H #include "asn1/asn1c/asn_application.h" -#include "asn1/asn1c/BOOLEAN.h" #ifdef __cplusplus extern "C" { #endif /* - * The value of the NULL type is meaningless: see BOOLEAN if you want to - * carry true/false semantics. + * The value of the NULL type is meaningless. + * Use the BOOLEAN type if you need to carry true/false semantics. */ typedef int NULL_t; extern asn_TYPE_descriptor_t asn_DEF_NULL; extern asn_TYPE_operation_t asn_OP_NULL; +asn_struct_free_f NULL_free; asn_struct_print_f NULL_print; asn_struct_compare_f NULL_compare; +ber_type_decoder_f NULL_decode_ber; der_type_encoder_f NULL_encode_der; xer_type_decoder_f NULL_decode_xer; xer_type_encoder_f NULL_encode_xer; @@ -32,8 +33,6 @@ per_type_decoder_f NULL_decode_uper; per_type_encoder_f NULL_encode_uper; asn_random_fill_f NULL_random_fill; -#define NULL_free BOOLEAN_free -#define NULL_decode_ber BOOLEAN_decode_ber #define NULL_constraint asn_generic_no_constraint #ifdef __cplusplus diff --git a/src/asn1/asn1c/ROAIPAddressFamily.c b/src/asn1/asn1c/ROAIPAddressFamily.c index d5d7c9be..cb3c0963 100644 --- a/src/asn1/asn1c/ROAIPAddressFamily.c +++ b/src/asn1/asn1c/ROAIPAddressFamily.c @@ -50,7 +50,7 @@ memb_addresses_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, if((size >= 1)) { /* Perform validation of the inner elements */ - return td->encoding_constraints.general_constraints(td, sptr, ctfailcb, app_key); + return SEQUENCE_OF_constraint(td, sptr, ctfailcb, app_key); } else { ASN__CTFAIL(app_key, td, sptr, "%s: constraint failed (%s:%d)", diff --git a/src/asn1/asn1c/RouteOriginAttestation.c b/src/asn1/asn1c/RouteOriginAttestation.c index 0fb07dea..da26f152 100644 --- a/src/asn1/asn1c/RouteOriginAttestation.c +++ b/src/asn1/asn1c/RouteOriginAttestation.c @@ -24,7 +24,7 @@ memb_ipAddrBlocks_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr if((size >= 1)) { /* Perform validation of the inner elements */ - return td->encoding_constraints.general_constraints(td, sptr, ctfailcb, app_key); + return SEQUENCE_OF_constraint(td, sptr, ctfailcb, app_key); } else { ASN__CTFAIL(app_key, td, sptr, "%s: constraint failed (%s:%d)", diff --git a/src/asn1/asn1c/asn_internal.h b/src/asn1/asn1c/asn_internal.h index 27360831..4e72d62f 100644 --- a/src/asn1/asn1c/asn_internal.h +++ b/src/asn1/asn1c/asn_internal.h @@ -7,8 +7,9 @@ */ #ifndef ASN_INTERNAL_H #define ASN_INTERNAL_H +#ifndef __EXTENSIONS__ #define __EXTENSIONS__ /* for Sun */ - +#endif #include "asn_application.h" /* Application-visible API */ #ifndef __NO_ASSERT_H__ /* Include assert.h only for internal use. */