comparison libtomcrypt/src/pk/asn1/der/sequence/der_decode_sequence_multi.c @ 1511:5916af64acd4 fuzz

merge from main
author Matt Johnston <matt@ucc.asn.au>
date Sat, 17 Feb 2018 19:29:51 +0800
parents 6dba84798cd5
children
comparison
equal deleted inserted replaced
1457:32f990cc96b1 1511:5916af64acd4
3 * LibTomCrypt is a library that provides various cryptographic 3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner. 4 * algorithms in a highly modular and flexible manner.
5 * 5 *
6 * The library is free for all purposes without any express 6 * The library is free for all purposes without any express
7 * guarantee it works. 7 * guarantee it works.
8 *
9 * Tom St Denis, [email protected], http://libtom.org
10 */ 8 */
11 #include "tomcrypt.h" 9 #include "tomcrypt.h"
12 #include <stdarg.h> 10 #include <stdarg.h>
13 11
14 12
23 Decode a SEQUENCE type using a VA list 21 Decode a SEQUENCE type using a VA list
24 @param in Input buffer 22 @param in Input buffer
25 @param inlen Length of input in octets 23 @param inlen Length of input in octets
26 @remark <...> is of the form <type, size, data> (int, unsigned long, void*) 24 @remark <...> is of the form <type, size, data> (int, unsigned long, void*)
27 @return CRYPT_OK on success 25 @return CRYPT_OK on success
28 */ 26 */
29 int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...) 27 int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...)
30 { 28 {
31 int err, type; 29 int err;
30 ltc_asn1_type type;
32 unsigned long size, x; 31 unsigned long size, x;
33 void *data; 32 void *data;
34 va_list args; 33 va_list args;
35 ltc_asn1_list *list; 34 ltc_asn1_list *list;
36 35
38 37
39 /* get size of output that will be required */ 38 /* get size of output that will be required */
40 va_start(args, inlen); 39 va_start(args, inlen);
41 x = 0; 40 x = 0;
42 for (;;) { 41 for (;;) {
43 type = va_arg(args, int); 42 type = (ltc_asn1_type)va_arg(args, int);
44 size = va_arg(args, unsigned long); 43 size = va_arg(args, unsigned long);
45 data = va_arg(args, void*); 44 data = va_arg(args, void*);
45 LTC_UNUSED_PARAM(size);
46 LTC_UNUSED_PARAM(data);
46 47
47 if (type == LTC_ASN1_EOL) { 48 if (type == LTC_ASN1_EOL) {
48 break; 49 break;
49 } 50 }
50 51
51 switch (type) { 52 switch (type) {
52 case LTC_ASN1_BOOLEAN: 53 case LTC_ASN1_BOOLEAN:
62 case LTC_ASN1_UTCTIME: 63 case LTC_ASN1_UTCTIME:
63 case LTC_ASN1_SET: 64 case LTC_ASN1_SET:
64 case LTC_ASN1_SETOF: 65 case LTC_ASN1_SETOF:
65 case LTC_ASN1_SEQUENCE: 66 case LTC_ASN1_SEQUENCE:
66 case LTC_ASN1_CHOICE: 67 case LTC_ASN1_CHOICE:
67 ++x; 68 case LTC_ASN1_RAW_BIT_STRING:
69 case LTC_ASN1_TELETEX_STRING:
70 case LTC_ASN1_GENERALIZEDTIME:
71 ++x;
68 break; 72 break;
69 73
70 default: 74 case LTC_ASN1_EOL:
75 case LTC_ASN1_CONSTRUCTED:
76 case LTC_ASN1_CONTEXT_SPECIFIC:
71 va_end(args); 77 va_end(args);
72 return CRYPT_INVALID_ARG; 78 return CRYPT_INVALID_ARG;
73 } 79 }
74 } 80 }
75 va_end(args); 81 va_end(args);
86 92
87 /* fill in the structure */ 93 /* fill in the structure */
88 va_start(args, inlen); 94 va_start(args, inlen);
89 x = 0; 95 x = 0;
90 for (;;) { 96 for (;;) {
91 type = va_arg(args, int); 97 type = (ltc_asn1_type)va_arg(args, int);
92 size = va_arg(args, unsigned long); 98 size = va_arg(args, unsigned long);
93 data = va_arg(args, void*); 99 data = va_arg(args, void*);
94 100
95 if (type == LTC_ASN1_EOL) { 101 if (type == LTC_ASN1_EOL) {
96 break; 102 break;
97 } 103 }
98 104
99 switch (type) { 105 switch (type) {
100 case LTC_ASN1_BOOLEAN: 106 case LTC_ASN1_BOOLEAN:
108 case LTC_ASN1_PRINTABLE_STRING: 114 case LTC_ASN1_PRINTABLE_STRING:
109 case LTC_ASN1_UTF8_STRING: 115 case LTC_ASN1_UTF8_STRING:
110 case LTC_ASN1_UTCTIME: 116 case LTC_ASN1_UTCTIME:
111 case LTC_ASN1_SEQUENCE: 117 case LTC_ASN1_SEQUENCE:
112 case LTC_ASN1_SET: 118 case LTC_ASN1_SET:
113 case LTC_ASN1_SETOF: 119 case LTC_ASN1_SETOF:
114 case LTC_ASN1_CHOICE: 120 case LTC_ASN1_CHOICE:
115 list[x].type = type; 121 case LTC_ASN1_RAW_BIT_STRING:
116 list[x].size = size; 122 case LTC_ASN1_TELETEX_STRING:
117 list[x++].data = data; 123 case LTC_ASN1_GENERALIZEDTIME:
124 LTC_SET_ASN1(list, x++, type, data, size);
118 break; 125 break;
119 126 /* coverity[dead_error_line] */
120 default: 127 case LTC_ASN1_EOL:
121 va_end(args); 128 case LTC_ASN1_CONSTRUCTED:
122 err = CRYPT_INVALID_ARG; 129 case LTC_ASN1_CONTEXT_SPECIFIC:
123 goto LBL_ERR; 130 break;
124 } 131 }
125 } 132 }
126 va_end(args); 133 va_end(args);
127 134
128 err = der_decode_sequence(in, inlen, list, x); 135 err = der_decode_sequence(in, inlen, list, x);
129 LBL_ERR:
130 XFREE(list); 136 XFREE(list);
131 return err; 137 return err;
132 } 138 }
133 139
134 #endif 140 #endif
135 141
136 142
137 /* $Source$ */ 143 /* ref: $Format:%D$ */
138 /* $Revision$ */ 144 /* git commit: $Format:%H$ */
139 /* $Date$ */ 145 /* commit time: $Format:%ai$ */