-/* tasn_utl.c */
/*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
* 2000.
#include <stddef.h>
#include <string.h>
+#include <internal/cryptlib.h>
#include <openssl/asn1.h>
#include <openssl/asn1t.h>
#include <openssl/objects.h>
#include <openssl/err.h>
+#include "asn1_locl.h"
/* Utility functions for manipulating fields and offsets */
{
const ASN1_AUX *aux;
int *lck, ret;
+ CRYPTO_RWLOCK **lock;
if ((it->itype != ASN1_ITYPE_SEQUENCE)
&& (it->itype != ASN1_ITYPE_NDEF_SEQUENCE))
return 0;
if (!aux || !(aux->flags & ASN1_AFLG_REFCOUNT))
return 0;
lck = offset2ptr(*pval, aux->ref_offset);
+ lock = offset2ptr(*pval, aux->ref_lock);
if (op == 0) {
*lck = 1;
+ *lock = CRYPTO_THREAD_lock_new();
+ if (*lock == NULL)
+ return 0;
return 1;
}
- ret = CRYPTO_add(lck, op, aux->ref_lock);
+ CRYPTO_atomic_add(lck, op, &ret, *lock);
#ifdef REF_PRINT
- fprintf(stderr, "%s: Reference Count: %d\n", it->sname, *lck);
-#endif
-#ifdef REF_CHECK
- if (ret < 0)
- fprintf(stderr, "%s, bad reference count\n", it->sname);
+ fprintf(stderr, "%p:%4d:%s\n", it, *lck, it->sname);
#endif
+ REF_ASSERT_ISNT(ret < 0);
+ if (ret == 0)
+ CRYPTO_THREAD_lock_free(*lock);
return ret;
}
ASN1_ENCODING *enc;
enc = asn1_get_enc_ptr(pval, it);
if (enc) {
- if (enc->enc)
- OPENSSL_free(enc->enc);
+ OPENSSL_free(enc->enc);
enc->enc = NULL;
enc->len = 0;
enc->modified = 1;
if (!enc)
return 1;
- if (enc->enc)
- OPENSSL_free(enc->enc);
+ OPENSSL_free(enc->enc);
enc->enc = OPENSSL_malloc(inlen);
- if (!enc->enc)
+ if (enc->enc == NULL)
return 0;
memcpy(enc->enc, in, inlen);
enc->len = inlen;
ASN1_VALUE **asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
{
ASN1_VALUE **pvaltmp;
- if (tt->flags & ASN1_TFLG_COMBINE)
- return pval;
pvaltmp = offset2ptr(*pval, tt->offset);
/*
* NOTE for BOOLEAN types the field is just a plain int so we can't
else
selector = ASN1_INTEGER_get((ASN1_INTEGER *)*sfld);
+ /* Let application callback translate value */
+ if (adb->adb_cb != NULL && adb->adb_cb(&selector) == 0) {
+ ASN1err(ASN1_F_ASN1_DO_ADB, ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE);
+ return NULL;
+ }
+
/*
* Try to find matching entry in table Maybe should check application
* types first to allow application override? Might also be useful to