From 0369a5291b525d2739e4ccb388761baaee86793f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Tue, 11 Nov 2014 22:17:26 +0100 Subject: [PATCH] Fix uninitialised pointer dereference --- ChangeLog | 5 +++++ library/asn1parse.c | 2 ++ tests/suites/test_suite_x509parse.data | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/ChangeLog b/ChangeLog index d3b7124b4..9821551c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,11 @@ PolarSSL ChangeLog (Sorted per branch, date) = PolarSSL 1.3.z branch +Security + * Fix remotely-triggerable uninitialised pointer dereference caused by + crafted X.509 certificate (server is not affected if it doesn't ask for a + client certificate) (found using Codenomicon Defensics). + Features * Add function pk_check_pair() to test if public and private keys match. diff --git a/library/asn1parse.c b/library/asn1parse.c index a3a2b56a2..e2117bfa1 100644 --- a/library/asn1parse.c +++ b/library/asn1parse.c @@ -278,6 +278,8 @@ int asn1_get_sequence_of( unsigned char **p, if( cur->next == NULL ) return( POLARSSL_ERR_ASN1_MALLOC_FAILED ); + memset( cur->next, 0, sizeof( asn1_sequence ) ); + cur = cur->next; } } diff --git a/tests/suites/test_suite_x509parse.data b/tests/suites/test_suite_x509parse.data index 4cc924fa4..c2bb7f320 100644 --- a/tests/suites/test_suite_x509parse.data +++ b/tests/suites/test_suite_x509parse.data @@ -869,6 +869,10 @@ X509 Certificate ASN1 (TBSCertificate v3, ext BasicContraint tag, octet len mism depends_on:POLARSSL_RSA_C x509parse_crt:"3081a230819fa0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bba317301530130603551d130101010409300702010102010100":"":POLARSSL_ERR_X509_INVALID_EXTENSIONS + POLARSSL_ERR_ASN1_LENGTH_MISMATCH +X509 Certificate ASN1 (ExtKeyUsage, bad second tag) +depends_on:POLARSSL_ECP_C:POLARSSL_ECP_DP_SECP256R1_ENABLED +x509parse_crt:"3081de3081dba003020102020900ebdbcd14105e1839300906072a8648ce3d0401300f310d300b0603550403130454657374301e170d3134313131313230353935345a170d3234313130383230353935345a300f310d300b06035504031304546573743059301306072a8648ce3d020106082a8648ce3d0301070342000437cc56d976091e5a723ec7592dff206eee7cf9069174d0ad14b5f768225962924ee500d82311ffea2fd2345d5d16bd8a88c26b770d55cd8a2a0efa01c8b4edffa321301f301d0603551d250416301406082b0601050507030107082b06010505070302":"":POLARSSL_ERR_X509_INVALID_EXTENSIONS + POLARSSL_ERR_ASN1_UNEXPECTED_TAG + X509 Certificate ASN1 (correct pubkey, no sig_alg) depends_on:POLARSSL_RSA_C x509parse_crt:"308183308180a0030201008204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff":"":POLARSSL_ERR_X509_INVALID_ALG + POLARSSL_ERR_ASN1_OUT_OF_DATA