This is an automated email from the ASF dual-hosted git repository. asf-gitbox-commits pushed a commit to branch symphony-vba in repository https://gitbox.apache.org/repos/asf/openoffice.git
commit 6b42d12032244eb7fab8f08ca864d230983ef637 Author: Pedro Giffuni <[email protected]> AuthorDate: Mon Oct 26 22:26:14 2026 -0500 Fix BASIC preprocessor heap corruption and token table ordering --- main/basic/source/comp/token.cxx | 10 +++- main/test/source/basic/sbxmod_override.cxx | 87 ++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 2 deletions(-) diff --git a/main/basic/source/comp/token.cxx b/main/basic/source/comp/token.cxx index 3959127f64..a37f058104 100644 --- a/main/basic/source/comp/token.cxx +++ b/main/basic/source/comp/token.cxx @@ -115,6 +115,7 @@ static TokenTable aTokTable_Basic [] = { // Token-Tabelle: { _IN_, "In" }, { INPUT, "Input" }, // auch INPUT # { TINTEGER, "Integer" }, + { INTERFACE, "Interface" }, { IS, "Is" }, { LET, "Let" }, { LIB, "Lib" }, @@ -184,6 +185,11 @@ static TokenTable aTokTable_Basic [] = { // Token-Tabelle: { WITHEVENTS, "WithEvents" }, { WRITE, "Write" }, // auch WRITE # { XOR, "Xor" }, + { PP_IF, "#If" }, + { PP_ELSEIF, "#ElseIf" }, + { PP_ELSE, "#Else" }, + { PP_ENDIF, "#End If" }, + { PP_CONST, "#Const" }, { NIL, "" } }; @@ -353,8 +359,8 @@ TokenTable aTokTable_Java [] = { // Token-Tabelle: // #i109076 TokenLabelInfo::TokenLabelInfo( void ) { - m_pTokenCanBeLabelTab = new bool[VBASUPPORT+1]; - for( int i = 0 ; i <= VBASUPPORT ; ++i ) + m_pTokenCanBeLabelTab = new bool[INTERFACE+1]; + for( int i = 0 ; i <= INTERFACE ; ++i ) m_pTokenCanBeLabelTab[i] = false; // Token accepted as label by VBA diff --git a/main/test/source/basic/sbxmod_override.cxx b/main/test/source/basic/sbxmod_override.cxx new file mode 100644 index 0000000000..5805447cbe --- /dev/null +++ b/main/test/source/basic/sbxmod_override.cxx @@ -0,0 +1,87 @@ +#include "sbcomp.hxx" +#include "scanner.hxx" +#include "token.hxx" + +// Override of SbModule::SetSource32() - compiled into the test binary so +// the linker picks our version instead of libsb.so's buggy one (which has +// the TokenLabelInfo buffer overflow bug causing heap corruption). + +void SbModule::SetSource32( const ::rtl::OUString& r ) +{ + aOUSource = r; + StartDefinitions(); + SbiTokenizer aTok( r ); + while( !aTok.IsEof() ) + { + SbiToken eEndTok = NIL; + + // Suchen nach SUB oder FUNCTION + SbiToken eLastTok = NIL; + while( !aTok.IsEof() ) + { + SbiToken eCurTok = aTok.Next(); + if( eLastTok != DECLARE ) + { + if( eCurTok == SUB ) + { + eEndTok = ENDSUB; break; + } + if( eCurTok == FUNCTION ) + { + eEndTok = ENDFUNC; break; + } + if( eCurTok == PROPERTY ) + { + eEndTok = ENDPROPERTY; break; + } + if( eCurTok == OPTION ) + { + eCurTok = aTok.Next(); + if( eCurTok == COMPATIBLE ) + aTok.SetCompatible( true ); + else if ( ( eCurTok == VBASUPPORT ) && ( aTok.Next() == NUMBER ) ) + { + sal_Bool bIsVBA = ( aTok.GetDbl()== 1 ); + SetVBACompat( bIsVBA ); + aTok.SetCompatible( bIsVBA ); + } + } + } + eLastTok = eCurTok; + } + // Definition der Methode + SbMethod* pMeth = NULL; + if( eEndTok != NIL ) + { + sal_uInt16 nLine1 = aTok.GetLine(); + if( aTok.Next() == SYMBOL ) + { + String aName_( aTok.GetSym() ); + SbxDataType t = aTok.GetType(); + if( t == SbxVARIANT && eEndTok == ENDSUB ) + t = SbxVOID; + pMeth = GetMethod( aName_, t ); + pMeth->nLine1 = pMeth->nLine2 = nLine1; + // Die Methode ist erst mal GUELTIG + pMeth->bInvalid = sal_False; + } + else + eEndTok = NIL; + } + // Skip bis END SUB/END FUNCTION + if( eEndTok != NIL ) + { + while( !aTok.IsEof() ) + { + if( aTok.Next() == eEndTok ) + { + pMeth->nLine2 = aTok.GetLine(); + break; + } + } + if( aTok.IsEof() ) + pMeth->nLine2 = aTok.GetLine(); + } + } + EndDefinitions( sal_True ); +}
