diff options
author | vlm <vlm@59561ff5-6e30-0410-9f3c-9617f08c8826> | 2005-12-07 05:46:03 +0000 |
---|---|---|
committer | vlm <vlm@59561ff5-6e30-0410-9f3c-9617f08c8826> | 2005-12-07 05:46:03 +0000 |
commit | 4d2ca1270e92d4996aa73ba867eaccf305f1ee5a (patch) | |
tree | 1ab58b0267d71e7793a03379262c95b2dd9de975 /skeletons/per_decoder.c | |
parent | 68a24641e44f346851add8c567ce221de8767126 (diff) |
added stack control to PER
git-svn-id: https://asn1c.svn.sourceforge.net/svnroot/asn1c/trunk@1022 59561ff5-6e30-0410-9f3c-9617f08c8826
Diffstat (limited to 'skeletons/per_decoder.c')
-rw-r--r-- | skeletons/per_decoder.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/skeletons/per_decoder.c b/skeletons/per_decoder.c index 55c04cb5..506ad674 100644 --- a/skeletons/per_decoder.c +++ b/skeletons/per_decoder.c @@ -1,2 +1,38 @@ #include <asn_application.h> +#include <asn_internal.h> #include <per_decoder.h> + +asn_dec_rval_t +uper_decode(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, void **sptr, const void *buffer, size_t size) { + asn_codec_ctx_t s_codec_ctx; + asn_per_data_t pd; + + /* + * Stack checker requires that the codec context + * must be allocated on the stack. + */ + if(opt_codec_ctx) { + if(opt_codec_ctx->max_stack_size) { + s_codec_ctx = *opt_codec_ctx; + opt_codec_ctx = &s_codec_ctx; + } + } else { + /* If context is not given, be security-conscious anyway */ + memset(&s_codec_ctx, 0, sizeof(s_codec_ctx)); + s_codec_ctx.max_stack_size = _ASN_DEFAULT_STACK_MAX; + opt_codec_ctx = &s_codec_ctx; + } + + /* Fill in the position indicator */ + pd.buffer = (const uint8_t *)buffer; + pd.nboff = 0; + pd.nbits = 8 * size; /* 8 is CHAR_BIT from <limits.h> */ + + /* + * Invoke type-specific decoder. + */ + if(!td->uper_decoder) + _ASN_DECODE_FAILED; /* PER is not compiled in */ + return td->uper_decoder(opt_codec_ctx, td, 0, sptr, &pd); +} + |