connectivity/source/drivers/dbase/DDatabaseMetaData.cxx | 120 +++++----- connectivity/source/drivers/dbase/DTable.cxx | 15 - connectivity/source/inc/dbase/DTable.hxx | 2 sc/qa/unit/data/wks/fail/sf_8acee7303920116c1f58c9d0e669855f-7551-minimized.wks |binary 4 files changed, 76 insertions(+), 61 deletions(-)
New commits: commit e46e041c9050a2a7c3223236100ce49a65f7e5d0 Author: Caolán McNamara <caol...@redhat.com> Date: Thu Sep 11 15:52:41 2014 +0100 reject invalid dbase files with 0 len db_slng right at the start Change-Id: If4aa5249391ea2d2e475fa3ebaccf4e9fc7442de diff --git a/connectivity/source/drivers/dbase/DTable.cxx b/connectivity/source/drivers/dbase/DTable.cxx index 845d037..54b5407 100644 --- a/connectivity/source/drivers/dbase/DTable.cxx +++ b/connectivity/source/drivers/dbase/DTable.cxx @@ -214,6 +214,8 @@ void ODbaseTable::readHeader() (*m_pFileStream).ReadUInt16( m_aHeader.db_slng ); if(ERRCODE_NONE != m_pFileStream->GetErrorCode()) throwInvalidDbaseFormat(); + if (m_aHeader.db_slng == 0) + throwInvalidDbaseFormat(); m_pFileStream->Read((char*)(&m_aHeader.db_frei), 20*sizeof(sal_uInt8)); if(ERRCODE_NONE != m_pFileStream->GetErrorCode()) throwInvalidDbaseFormat(); @@ -1497,9 +1499,9 @@ bool ODbaseTable::DropImpl() bool ODbaseTable::InsertRow(OValueRefVector& rRow, bool bFlush, const Reference<XIndexAccess>& _xCols) { // fill buffer with blanks - AllocBuffer(); - if (!m_pBuffer) + if (!AllocBuffer()) return false; + memset(m_pBuffer, 0, m_aHeader.db_slng); m_pBuffer[0] = ' '; @@ -1556,7 +1558,8 @@ bool ODbaseTable::InsertRow(OValueRefVector& rRow, bool bFlush, const Reference< bool ODbaseTable::UpdateRow(OValueRefVector& rRow, OValueRefRow& pOrgRow, const Reference<XIndexAccess>& _xCols) { // fill buffer with blanks - AllocBuffer(); + if (!AllocBuffer()) + return false; // position on desired record: sal_Size nPos = m_aHeader.db_kopf + (long)(m_nFilePos-1) * m_aHeader.db_slng; @@ -2743,10 +2746,10 @@ bool ODbaseTable::ReadMemo(sal_Size nBlockNo, ORowSetValue& aVariable) return true; } -void ODbaseTable::AllocBuffer() +bool ODbaseTable::AllocBuffer() { sal_uInt16 nSize = m_aHeader.db_slng; - OSL_ENSURE(nSize > 0, "Size too small"); + SAL_WARN_IF(nSize == 0, "connectivity.drivers", "Size too small"); if (m_nBufferSize != nSize) { @@ -2760,6 +2763,8 @@ void ODbaseTable::AllocBuffer() m_nBufferSize = nSize; m_pBuffer = new sal_uInt8[m_nBufferSize+1]; } + + return m_pBuffer != NULL; } bool ODbaseTable::WriteBuffer() diff --git a/connectivity/source/inc/dbase/DTable.hxx b/connectivity/source/inc/dbase/DTable.hxx index 4f2635e..915503d 100644 --- a/connectivity/source/inc/dbase/DTable.hxx +++ b/connectivity/source/inc/dbase/DTable.hxx @@ -112,7 +112,7 @@ namespace connectivity bool WriteBuffer(); bool UpdateBuffer(OValueRefVector& rRow, OValueRefRow pOrgRow,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>& _xCols, bool bForceAllFields); ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> isUniqueByColumnName(sal_Int32 _nColumnPos); - void AllocBuffer(); + bool AllocBuffer(); void throwInvalidDbaseFormat(); void SAL_CALL renameImpl( const OUString& newName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException); diff --git a/sc/qa/unit/data/wks/fail/sf_8acee7303920116c1f58c9d0e669855f-7551-minimized.wks b/sc/qa/unit/data/wks/fail/sf_8acee7303920116c1f58c9d0e669855f-7551-minimized.wks new file mode 100644 index 0000000..d72176d Binary files /dev/null and b/sc/qa/unit/data/wks/fail/sf_8acee7303920116c1f58c9d0e669855f-7551-minimized.wks differ commit e7fb96a1c93f57b1ffc6c0bd2af578d6a3e4f78b Author: Caolán McNamara <caol...@redhat.com> Date: Thu Sep 11 16:37:00 2014 +0100 ODbaseDatabaseMetaData::getColumns dies if throwInvalidDbaseFormat occurs Change-Id: If649c1cb8f41e8a29afb5ad350664a573cd1102a diff --git a/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx b/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx index 00f3341..bc37bdb 100644 --- a/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx +++ b/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx @@ -18,6 +18,7 @@ */ #include "dbase/DDatabaseMetaData.hxx" +#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/sdbc/DataType.hpp> #include <com/sun/star/sdbc/ResultSetType.hpp> #include <com/sun/star/sdbc/ColumnValue.hpp> @@ -157,7 +158,6 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumns( { ::osl::MutexGuard aGuard( m_aMutex ); - Reference< XTablesSupplier > xTables = m_pConnection->createCatalog(); if(!xTables.is()) throw SQLException(); @@ -169,72 +169,82 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumns( ODatabaseMetaDataResultSet::ORows aRows; ODatabaseMetaDataResultSet::ORow aRow(19); - aRow[10] = new ORowSetValueDecorator((sal_Int32)10); - Sequence< OUString> aTabNames(xNames->getElementNames()); - const OUString* pTabBegin = aTabNames.getConstArray(); - const OUString* pTabEnd = pTabBegin + aTabNames.getLength(); - for(;pTabBegin != pTabEnd;++pTabBegin) + try { - if(match(tableNamePattern,*pTabBegin,'\0')) + aRow[10] = new ORowSetValueDecorator((sal_Int32)10); + Sequence< OUString> aTabNames(xNames->getElementNames()); + const OUString* pTabBegin = aTabNames.getConstArray(); + const OUString* pTabEnd = pTabBegin + aTabNames.getLength(); + for(;pTabBegin != pTabEnd;++pTabBegin) { - Reference< XColumnsSupplier> xTable( - xNames->getByName(*pTabBegin), css::uno::UNO_QUERY); - OSL_ENSURE(xTable.is(),"Table not found! Normallya exception had to be thrown here!"); - aRow[3] = new ORowSetValueDecorator(*pTabBegin); + if(match(tableNamePattern,*pTabBegin,'\0')) + { + Reference< XColumnsSupplier> xTable( + xNames->getByName(*pTabBegin), css::uno::UNO_QUERY); + OSL_ENSURE(xTable.is(),"Table not found! Normallya exception had to be thrown here!"); + aRow[3] = new ORowSetValueDecorator(*pTabBegin); - Reference< XNameAccess> xColumns = xTable->getColumns(); - if(!xColumns.is()) - throw SQLException(); + Reference< XNameAccess> xColumns = xTable->getColumns(); + if(!xColumns.is()) + throw SQLException(); - Sequence< OUString> aColNames(xColumns->getElementNames()); + Sequence< OUString> aColNames(xColumns->getElementNames()); - const OUString* pBegin = aColNames.getConstArray(); - const OUString* pEnd = pBegin + aColNames.getLength(); - Reference< XPropertySet> xColumn; - for(sal_Int32 i=1;pBegin != pEnd;++pBegin,++i) - { - if(match(columnNamePattern,*pBegin,'\0')) + const OUString* pBegin = aColNames.getConstArray(); + const OUString* pEnd = pBegin + aColNames.getLength(); + Reference< XPropertySet> xColumn; + for(sal_Int32 i=1;pBegin != pEnd;++pBegin,++i) { - aRow[4] = new ORowSetValueDecorator(*pBegin); - - xColumn.set( - xColumns->getByName(*pBegin), css::uno::UNO_QUERY); - OSL_ENSURE(xColumn.is(),"Columns contains a column who isn't a fastpropertyset!"); - aRow[5] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)))); - aRow[6] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)))); - aRow[7] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)))); - aRow[9] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)))); - aRow[11] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE)))); - aRow[13] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)))); - switch((sal_Int32)aRow[5]->getValue()) + if(match(columnNamePattern,*pBegin,'\0')) { - case DataType::CHAR: - case DataType::VARCHAR: - aRow[16] = new ORowSetValueDecorator((sal_Int32)254); - break; - case DataType::LONGVARCHAR: - aRow[16] = new ORowSetValueDecorator((sal_Int32)65535); - break; - default: - aRow[16] = new ORowSetValueDecorator((sal_Int32)0); + aRow[4] = new ORowSetValueDecorator(*pBegin); + + xColumn.set( + xColumns->getByName(*pBegin), css::uno::UNO_QUERY); + OSL_ENSURE(xColumn.is(),"Columns contains a column who isn't a fastpropertyset!"); + aRow[5] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)))); + aRow[6] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)))); + aRow[7] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)))); + aRow[9] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)))); + aRow[11] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE)))); + aRow[13] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)))); + switch((sal_Int32)aRow[5]->getValue()) + { + case DataType::CHAR: + case DataType::VARCHAR: + aRow[16] = new ORowSetValueDecorator((sal_Int32)254); + break; + case DataType::LONGVARCHAR: + aRow[16] = new ORowSetValueDecorator((sal_Int32)65535); + break; + default: + aRow[16] = new ORowSetValueDecorator((sal_Int32)0); + } + aRow[17] = new ORowSetValueDecorator(i); + switch(sal_Int32(aRow[11]->getValue())) + { + case ColumnValue::NO_NULLS: + aRow[18] = new ORowSetValueDecorator(OUString("NO")); + break; + case ColumnValue::NULLABLE: + aRow[18] = new ORowSetValueDecorator(OUString("YES")); + break; + default: + aRow[18] = new ORowSetValueDecorator(OUString()); + } + aRows.push_back(aRow); } - aRow[17] = new ORowSetValueDecorator(i); - switch(sal_Int32(aRow[11]->getValue())) - { - case ColumnValue::NO_NULLS: - aRow[18] = new ORowSetValueDecorator(OUString("NO")); - break; - case ColumnValue::NULLABLE: - aRow[18] = new ORowSetValueDecorator(OUString("YES")); - break; - default: - aRow[18] = new ORowSetValueDecorator(OUString()); - } - aRows.push_back(aRow); } } } } + catch (const WrappedTargetException& e) + { + SQLException aSql; + if (e.TargetException >>= aSql) + throw aSql; + throw WrappedTargetRuntimeException(e.Message, e.Context, e.TargetException); + } ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns); Reference< XResultSet > xRef = pResult; pResult->setRows(aRows);
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits