asn1: tagnum size has not exceed 3 bytes
3 bytes is the size of SC_ASN1_TAG_MASK used when composing the asn1 templates with 'struct sc_asn1_entry'. With this limitation maximal supported ASN.1 tag number is 2^^14-1 . Fixed 'dead-code' coverity-scan issue. Close #707
This commit is contained in:
parent
196e476330
commit
f98c8cd37c
|
@ -73,14 +73,17 @@ int sc_asn1_read_tag(const u8 ** buf, size_t buflen, unsigned int *cla_out,
|
||||||
*tag_out = SC_ASN1_TAG_EOC;
|
*tag_out = SC_ASN1_TAG_EOC;
|
||||||
return SC_SUCCESS;
|
return SC_SUCCESS;
|
||||||
}
|
}
|
||||||
/* parse tag byte(s) */
|
/* parse tag byte(s)
|
||||||
|
* Resulted tag is presented by integer that has not to be
|
||||||
|
* confused with the 'tag number' part of ASN.1 tag.
|
||||||
|
*/
|
||||||
cla = (*p & SC_ASN1_TAG_CLASS) | (*p & SC_ASN1_TAG_CONSTRUCTED);
|
cla = (*p & SC_ASN1_TAG_CLASS) | (*p & SC_ASN1_TAG_CONSTRUCTED);
|
||||||
tag = *p & SC_ASN1_TAG_PRIMITIVE;
|
tag = *p & SC_ASN1_TAG_PRIMITIVE;
|
||||||
p++;
|
p++;
|
||||||
left--;
|
left--;
|
||||||
if (tag == SC_ASN1_TAG_PRIMITIVE) {
|
if (tag == SC_ASN1_TAG_PRIMITIVE) {
|
||||||
/* high tag number */
|
/* high tag number */
|
||||||
size_t n = sizeof(int) - 1;
|
size_t n = SC_ASN1_TAGNUM_SIZE - 1;
|
||||||
/* search the last tag octet */
|
/* search the last tag octet */
|
||||||
while (left-- != 0 && n != 0) {
|
while (left-- != 0 && n != 0) {
|
||||||
tag <<= 8;
|
tag <<= 8;
|
||||||
|
@ -93,10 +96,8 @@ int sc_asn1_read_tag(const u8 ** buf, size_t buflen, unsigned int *cla_out,
|
||||||
/* either an invalid tag or it doesn't fit in
|
/* either an invalid tag or it doesn't fit in
|
||||||
* unsigned int */
|
* unsigned int */
|
||||||
return SC_ERROR_INVALID_ASN1_OBJECT;
|
return SC_ERROR_INVALID_ASN1_OBJECT;
|
||||||
|
|
||||||
}
|
}
|
||||||
if (left == 0)
|
|
||||||
return SC_ERROR_INVALID_ASN1_OBJECT;
|
|
||||||
/* parse length byte(s) */
|
/* parse length byte(s) */
|
||||||
len = *p & 0x7f;
|
len = *p & 0x7f;
|
||||||
if (*p++ & 0x80) {
|
if (*p++ & 0x80) {
|
||||||
|
|
|
@ -135,6 +135,7 @@ int sc_asn1_sig_value_sequence_to_rs(struct sc_context *ctx,
|
||||||
#define SC_ASN1_CONS 0x01000000
|
#define SC_ASN1_CONS 0x01000000
|
||||||
|
|
||||||
#define SC_ASN1_TAG_MASK 0x00FFFFFF
|
#define SC_ASN1_TAG_MASK 0x00FFFFFF
|
||||||
|
#define SC_ASN1_TAGNUM_SIZE 3
|
||||||
|
|
||||||
#define SC_ASN1_PRESENT 0x00000001
|
#define SC_ASN1_PRESENT 0x00000001
|
||||||
#define SC_ASN1_OPTIONAL 0x00000002
|
#define SC_ASN1_OPTIONAL 0x00000002
|
||||||
|
|
Loading…
Reference in New Issue