From nobody Mon Sep 17 00:00:00 2001 From: Pavel Rebriy Date: Wed, 28 Jun 2006 17:57:49 +0400 Subject: [PATCH] Verifier: add check for empty initialization method - Adds verification for emtry constructor of class. - Improves verifier error massages. --- vm/vmcore/src/verifier/ver_dataflow.cpp | 15 ++++++++++++++- vm/vmcore/src/verifier/ver_utils.cpp | 7 +++++-- 2 files changed, 19 insertions(+), 3 deletions(-) 50b304b9674adfedd998c0fb1c398786bf9e2e41 diff --git a/vm/vmcore/src/verifier/ver_dataflow.cpp b/vm/vmcore/src/verifier/ver_dataflow.cpp index 645a5fc..3f1d3a8 100644 --- a/vm/vmcore/src/verifier/ver_dataflow.cpp +++ b/vm/vmcore/src/verifier/ver_dataflow.cpp @@ -1115,6 +1115,19 @@ vf_check_end_node_data_flow( unsigned no return VER_OK; } + // check method + if( !memcmp( method_get_name( ctex->m_method ), "", 7 ) + && ctex->m_vtype.m_class != ctex->m_vtype.m_object ) + { + if( invector->m_local->m_type == SM_UNINITIALIZED ) { + VERIFY_REPORT( ctex, "(class: " << class_get_name( ctex->m_class ) + << ", method: " << method_get_name( ctex->m_method ) + << method_get_descriptor( ctex->m_method ) + << ") Constructor must be invoked" ); + return VER_ErrorDataFlow; + } + } + // get first instruction vf_Code_t *instr = &ctex->m_code[ctex->m_graph->GetNodeFirstInstr( node_num )]; @@ -1336,7 +1349,7 @@ vf_create_method_begin_vector( vf_Contex // fill "this" entry const char *name = class_get_name( ctex->m_class ); vf_ValidType_t *type = vf_create_class_valid_type( name, ctex ); - if( !strcmp( method_get_name( ctex->m_method ), "" ) ) { + if( !memcmp( method_get_name( ctex->m_method ), "", 7 ) ) { vector->m_local->m_type = SM_UNINITIALIZED; } else { vector->m_local->m_type = SM_REF; diff --git a/vm/vmcore/src/verifier/ver_utils.cpp b/vm/vmcore/src/verifier/ver_utils.cpp index 44e7813..604edc3 100644 --- a/vm/vmcore/src/verifier/ver_utils.cpp +++ b/vm/vmcore/src/verifier/ver_utils.cpp @@ -344,6 +344,7 @@ vf_TypePool::DumpTypeConstraints( ostrea { *out << "CONSTRAINT: have \"" << constraint->source << "\" need \"" << constraint->target << "\" for method " + << class_get_name( method_get_class( m_method ) ) << "." << method_get_name( m_method ) << method_get_descriptor( m_method ) << endl; } return; @@ -411,10 +412,12 @@ vf_TypePool::SetRestriction( const char VERIFY_TRACE( "constraint", "CONSTRAINT: for class \"" << class_get_name( method_get_class( m_method ) ) << "\" CP index #" << index << " check access: have \"" << source << "\" need \"" << target << "\" for method " + << class_get_name( method_get_class( m_method ) ) << "." << method_get_name( m_method ) << method_get_descriptor( m_method ) ); } else { VERIFY_TRACE( "constraint", "CONSTRAINT: have \"" << source << "\" need \"" << target << "\" for method " + << class_get_name( method_get_class( m_method ) ) << "." << method_get_name( m_method ) << method_get_descriptor( m_method ) ); } return; @@ -1222,7 +1225,7 @@ vf_check_access_constraint( const char * VERIFY_DEBUG( "verifying class " << class_get_name( ctex->m_class ) << " (method " << method_get_name( ctex->m_method ) << method_get_descriptor( ctex->m_method ) - << ") couldn't resolve field by constant pool index #" << index ); + << ") couldn't resolve field with constant pool index #" << index ); return VER_OK; } if( field_is_protected( field ) ) { @@ -1235,7 +1238,7 @@ vf_check_access_constraint( const char * VERIFY_DEBUG( "verifying class " << class_get_name( ctex->m_class ) << " (method " << method_get_name( ctex->m_method ) << method_get_descriptor( ctex->m_method ) - << ") couldn't resolve method by constant pool index #" << index ); + << ") couldn't resolve method with constant pool index #" << index ); return VER_OK; } if( method_is_protected( method ) ) { -- 1.3.3