From: Greg Hudson Date: Thu, 8 Mar 2012 00:37:47 +0000 (+0000) Subject: Properly decode etype-info2 with no salt X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9220e0c6eaac565f9241e09e0809f206b121eb2c;p=krb5.git Properly decode etype-info2 with no salt The data-driven decoder for etype-info2 was neglecting to call init_no_salt() when no salt is present in the encoding. Add in the missing call. Also add decode test cases for etype-info2, which would have caught this if they weren't missing. ticket: 7100 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25744 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/asn.1/asn1_k_encode.c b/src/lib/krb5/asn.1/asn1_k_encode.c index 35667ffa5..467e2de6d 100644 --- a/src/lib/krb5/asn.1/asn1_k_encode.c +++ b/src/lib/krb5/asn.1/asn1_k_encode.c @@ -602,7 +602,8 @@ DEFSEQTYPE(etype_info_entry, krb5_etype_info_entry, etype_info_entry_fields); /* First field is the same as etype-info. */ DEFCNFIELD(etype_info2_1_def, krb5_etype_info_entry, salt, length, 1, u_generalstring); -DEFOPTIONALTYPE(etype_info2_1, is_salt_present, NULL, etype_info2_1_def); +DEFOPTIONALTYPE(etype_info2_1, is_salt_present, init_no_salt, + etype_info2_1_def); DEFFIELD(etype_info2_2, krb5_etype_info_entry, s2kparams, 2, opt_ostring_data); static const struct atype_info *etype_info2_entry_fields[] = { &k5_atype_etype_info_0, &k5_atype_etype_info2_1, &k5_atype_etype_info2_2 diff --git a/src/tests/asn.1/krb5_decode_test.c b/src/tests/asn.1/krb5_decode_test.c index 19313ee29..87d3bc458 100644 --- a/src/tests/asn.1/krb5_decode_test.c +++ b/src/tests/asn.1/krb5_decode_test.c @@ -858,6 +858,46 @@ int main(argc, argv) ktest_destroy_etype_info(ref); } + /****************************************************************/ + /* decode_etype_info2 */ + { + krb5_etype_info ref, var; + + ktest_make_sample_etype_info2(&ref); + retval = krb5_data_hex_parse(&code,"30 51 30 1E A0 03 02 01 00 A1 0D 1B 0B 4D 6F 72 74 6F 6E 27 73 20 23 30 A2 08 04 06 73 32 6B 3A 20 30 30 0F A0 03 02 01 01 A2 08 04 06 73 32 6B 3A 20 31 30 1E A0 03 02 01 02 A1 0D 1B 0B 4D 6F 72 74 6F 6E 27 73 20 23 32 A2 08 04 06 73 32 6B 3A 20 32"); + if (retval) { + com_err("krb5_decode_test", retval, "while parsing etype_info2"); + exit(1); + } + retval = decode_krb5_etype_info2(&code,&var); + if (retval) { + com_err("krb5_decode_test", retval, "while decoding etype_info2"); + } + test(ktest_equal_etype_info(ref,var),"etype_info2\n"); + + ktest_destroy_etype_info(var); + ktest_destroy_etype_info_entry(ref[2]); ref[2] = 0; + ktest_destroy_etype_info_entry(ref[1]); ref[1] = 0; + krb5_free_data_contents(test_context, &code); + + retval = krb5_data_hex_parse(&code,"30 20 30 1E A0 03 02 01 00 A1 0D 1B 0B 4D 6F 72 74 6F 6E 27 73 20 23 30 A2 08 04 06 73 32 6B 3A 20 30"); + if (retval) { + com_err("krb5_decode_test", retval, + "while parsing etype_info2 (only one)"); + exit(1); + } + retval = decode_krb5_etype_info2(&code,&var); + if (retval) { + com_err("krb5_decode_test", retval, + "while decoding etype_info2 (only one)"); + } + test(ktest_equal_etype_info(ref,var),"etype_info2 (only one)\n"); + + krb5_free_data_contents(test_context, &code); + ktest_destroy_etype_info(var); + ktest_destroy_etype_info(ref); + } + /****************************************************************/ /* decode_pa_enc_ts */ {