@@ -135,6 +135,53 @@ static unsigned char * hex2bin (char *hexstr, unsigned char *binvalue,
135135 return (binvalue );
136136}
137137
138+ static uint32_t decode_length_field (uint8_t * lenstart , uint32_t maxrem ,
139+ int * lenlen ) {
140+
141+ uint8_t lenoctets ;
142+ uint8_t byte ;
143+ uint32_t result = 0 ;
144+ int i ;
145+
146+ if (maxrem == 0 ) {
147+ * lenlen = 0 ;
148+ return 0 ;
149+ }
150+
151+ byte = * lenstart ;
152+ if ((byte & 0x80 ) == 0 ) {
153+ /* definite short form */
154+ * lenlen = 1 ;
155+ return (byte & 0x7f );
156+ }
157+ lenoctets = byte ;
158+ if (lenoctets ) {
159+ /* definite long form */
160+ if (lenoctets > 8 ) {
161+ fprintf (stderr , "libwandder cannot decode length fields longer than 8 bytes!\n" );
162+ * lenlen = 0 ;
163+ return 0 ;
164+ }
165+ if (lenoctets > maxrem ) {
166+ fprintf (stderr , "libwandder: length field size is larger than the amount of bytes remaining in the current field? (%u vs %u)\n" , lenoctets , maxrem );
167+ * lenlen = 0 ;
168+ return 0 ;
169+ }
170+ * lenlen = lenoctets + 1 ;
171+ for (i = 0 ; i < (int )lenoctets ; i ++ ) {
172+ byte = * (lenstart + i + 1 );
173+ result = result << 8 ;
174+ result |= (byte );
175+ }
176+ } else {
177+ /* indefinite form */
178+ * lenlen = 1 ;
179+ result = 0xFFFFFFFF ;
180+ }
181+
182+ return result ;
183+ }
184+
138185static inline int decrypt_length_sanity_check (uint8_t * data , uint64_t dlen ) {
139186
140187 uint64_t obslen = 0 , headerlen = 0 , gap = 0 ;
@@ -1495,8 +1542,6 @@ static char *stringify_sequenced_primitives(char *sequence_name,
14951542
14961543 wandder_item_t * parent = dec -> current ;
14971544 uint8_t * ptr = (uint8_t * )(parent -> valptr );
1498- int64_t nextint ;
1499- uint32_t nextintlen ;
15001545 char * writer = space ;
15011546 int namelen = strlen (sequence_name );
15021547 int first = 1 ;
@@ -1516,6 +1561,9 @@ static char *stringify_sequenced_primitives(char *sequence_name,
15161561 while (ptr - parent -> valptr < parent -> length ) {
15171562 char tmp [1024 ];
15181563 int tmplen ;
1564+ int64_t nextint ;
1565+ uint32_t nextintlen ;
1566+
15191567 assert ((* ptr ) == WANDDER_TAG_INTEGER );
15201568 ptr ++ ;
15211569 /* integer len should always be a single byte (?) */
@@ -1539,6 +1587,38 @@ static char *stringify_sequenced_primitives(char *sequence_name,
15391587 }
15401588 ptr += nextintlen ;
15411589 }
1590+ } else if (interpretas == WANDDER_TAG_UTF8STR ) {
1591+ while (ptr - parent -> valptr < parent -> length ) {
1592+ int lenlen = 0 ;
1593+ uint32_t strlength = 0 ;
1594+
1595+ assert ((* ptr ) == WANDDER_TAG_UTF8STR );
1596+ ptr ++ ;
1597+
1598+ strlength = decode_length_field (ptr ,
1599+ parent -> length - (ptr - parent -> valptr ), & lenlen );
1600+
1601+ if (strlength == 0 ) {
1602+ break ;
1603+ } else if (strlength == 0xFFFFFFFF ) {
1604+ /* TODO handle indefinite length fields... */
1605+ break ;
1606+ }
1607+ ptr += lenlen ;
1608+ if (spacelen - (writer - space ) > strlength + 2 ) {
1609+ if (!first ) {
1610+ * writer = ',' ;
1611+ writer ++ ;
1612+ * writer = ' ' ;
1613+ writer ++ ;
1614+ } else {
1615+ first = 0 ;
1616+ }
1617+ memcpy (writer , ptr , strlength );
1618+ writer += strlength ;
1619+ }
1620+ ptr += strlength ;
1621+ }
15421622 }
15431623
15441624 /* TODO add code for other primitive types if they crop up */
@@ -2581,7 +2661,6 @@ static void free_dumpers(wandder_etsispec_t *dec) {
25812661 free (dec -> ipiri .members );
25822662 free (dec -> emailiri .members );
25832663 free (dec -> emailcc .members );
2584- free (dec -> emailrecipientsingle .members );
25852664 free (dec -> aaainformation .members );
25862665 free (dec -> pop3aaainformation .members );
25872666 free (dec -> asmtpaaainformation .members );
@@ -4109,8 +4188,8 @@ static void init_dumpers(wandder_etsispec_t *dec) {
41094188 dec -> emailiri .members [10 ] =
41104189 (struct wandder_dump_action ) {
41114190 .name = "e-mail-Recipients" ,
4112- . descend = & ( dec -> emailrecipients ) ,
4113- .interpretas = WANDDER_TAG_NULL
4191+ NULL ,
4192+ .interpretas = WANDDER_TAG_UTF8STR
41144193 };
41154194 dec -> emailiri .members [11 ] =
41164195 (struct wandder_dump_action ) {
@@ -4159,21 +4238,11 @@ static void init_dumpers(wandder_etsispec_t *dec) {
41594238 dec -> emailrecipients .membercount = 0 ;
41604239 dec -> emailrecipients .members = NULL ;
41614240 dec -> emailrecipients .sequence =
4162- (struct wandder_dump_action ) {
4163- .name = "E-mail-Address-List" ,
4164- .descend = & (dec -> emailrecipientsingle ),
4165- .interpretas = WANDDER_TAG_NULL
4166- };
4167-
4168- dec -> emailrecipientsingle .membercount = 1 ;
4169- ALLOC_MEMBERS (dec -> emailrecipientsingle );
4170- dec -> emailrecipientsingle .members [0 ] =
41714241 (struct wandder_dump_action ) {
41724242 .name = "recipient" ,
41734243 .descend = NULL ,
41744244 .interpretas = WANDDER_TAG_UTF8STR
41754245 };
4176- dec -> emailrecipientsingle .sequence = WANDDER_NOACTION ;
41774246
41784247 dec -> aaainformation .membercount = 3 ;
41794248 ALLOC_MEMBERS (dec -> aaainformation );
0 commit comments