Fix potential integer overflow parsing DER CRT
This patch prevents a potential signed integer overflow during the
certificate version verification checks.
diff --git a/library/x509_crt.c b/library/x509_crt.c
index 8fa63c5..2b3eef7 100644
--- a/library/x509_crt.c
+++ b/library/x509_crt.c
@@ -619,14 +619,14 @@
return( ret );
}
- crt->version++;
-
- if( crt->version > 3 )
+ if( crt->version < 0 || crt->version > 2 )
{
x509_crt_free( crt );
return( POLARSSL_ERR_X509_UNKNOWN_VERSION );
}
+ crt->version++;
+
if( ( ret = x509_get_sig_alg( &crt->sig_oid1, &sig_params1,
&crt->sig_md, &crt->sig_pk,
&crt->sig_opts ) ) != 0 )