diff options
author | Kai Sommerfeld <kso@openoffice.org> | 2009-11-03 13:57:46 +0100 |
---|---|---|
committer | Kai Sommerfeld <kso@openoffice.org> | 2009-11-03 13:57:46 +0100 |
commit | c1cd47e83dfddfb13f4e61391fd50f7b5019df1e (patch) | |
tree | c889b91372724f76101ae57db2ba63a98247da3f /ucb/source/ucp/ftp/ftpinpstr.cxx | |
parent | 229aa1ebdffbf985ccb7af483b41cef9d18ce0e7 (diff) |
#106429# - unchecked read in FTPInputStream::readBytes
Diffstat (limited to 'ucb/source/ucp/ftp/ftpinpstr.cxx')
-rw-r--r-- | ucb/source/ucp/ftp/ftpinpstr.cxx | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/ucb/source/ucp/ftp/ftpinpstr.cxx b/ucb/source/ucp/ftp/ftpinpstr.cxx index 7600ddb6af..2f7a82baa2 100644 --- a/ucb/source/ucp/ftp/ftpinpstr.cxx +++ b/ucb/source/ucp/ftp/ftpinpstr.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2008 by Sun Microsystems, Inc. * * OpenOffice.org - a multi-platform office productivity suite @@ -53,11 +53,11 @@ using namespace com::sun::star::io; FTPInputStream::FTPInputStream(FILE* tmpfl) - : m_tmpfl(tmpfl ? tmpfl : tmpfile()) + : m_tmpfl(tmpfl ? tmpfl : tmpfile()) { fseek(m_tmpfl,0,SEEK_END); -// fpos_t pos; -// fgetpos(m_tmpfl,&pos); +// fpos_t pos; +// fgetpos(m_tmpfl,&pos); long pos = ftell(m_tmpfl); rewind(m_tmpfl); m_nLength = sal_Int64(pos); @@ -65,24 +65,24 @@ FTPInputStream::FTPInputStream(FILE* tmpfl) -FTPInputStream::~FTPInputStream() +FTPInputStream::~FTPInputStream() { if ( 0 != m_tmpfl) fclose(m_tmpfl); } -Any SAL_CALL FTPInputStream::queryInterface( +Any SAL_CALL FTPInputStream::queryInterface( const Type& rType ) throw( - RuntimeException - ) + RuntimeException + ) { Any aRet = ::cppu::queryInterface(rType, SAL_STATIC_CAST( XInputStream*,this ), SAL_STATIC_CAST( XSeekable*,this ) ); - + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); } @@ -107,26 +107,29 @@ sal_Int32 SAL_CALL FTPInputStream::readBytes(Sequence< sal_Int8 >& aData, RuntimeException) { osl::MutexGuard aGuard(m_aMutex); - + if(0 <= nBytesToRead && aData.getLength() < nBytesToRead) - aData.realloc(nBytesToRead); - + aData.realloc(nBytesToRead); + // fpos_t bpos,epos; - + // fgetpos(m_tmpfl,&bpos); -// fread(aData.getArray(),nBytesToRead,1,m_tmpfl); +// fread(aData.getArray(),nBytesToRead,1,m_tmpfl); // fgetpos(m_tmpfl,&epos); long bpos,epos; - + bpos = ftell(m_tmpfl); - fread(aData.getArray(),nBytesToRead,1,m_tmpfl); + if (fread(aData.getArray(),nBytesToRead,1,m_tmpfl) != 1) + throw IOException(); + epos = ftell(m_tmpfl); - + return sal_Int32(epos-bpos); } -sal_Int32 SAL_CALL FTPInputStream::readSomeBytes( Sequence< sal_Int8 >& aData,sal_Int32 nMaxBytesToRead ) +sal_Int32 SAL_CALL FTPInputStream::readSomeBytes( Sequence< sal_Int8 >& aData, + sal_Int32 nMaxBytesToRead ) throw( NotConnectedException, BufferSizeExceededException, IOException, @@ -146,7 +149,7 @@ void SAL_CALL FTPInputStream::skipBytes(sal_Int32 nBytesToSkip) osl::MutexGuard aGuard(m_aMutex); if(!m_tmpfl) throw IOException(); - + fseek(m_tmpfl,long(nBytesToSkip),SEEK_CUR); } @@ -155,7 +158,7 @@ void SAL_CALL FTPInputStream::skipBytes(sal_Int32 nBytesToSkip) sal_Int32 SAL_CALL FTPInputStream::available(void) throw(NotConnectedException, IOException, - RuntimeException) + RuntimeException) { return sal::static_int_cast<sal_Int32>(m_nLength - getPosition()); } @@ -177,12 +180,12 @@ void SAL_CALL FTPInputStream::closeInput(void) void SAL_CALL FTPInputStream::seek(sal_Int64 location) throw( IllegalArgumentException, IOException, - RuntimeException ) + RuntimeException ) { osl::MutexGuard aGuard(m_aMutex); if(!m_tmpfl) throw IOException(); - + fseek(m_tmpfl,long(location),SEEK_SET); } @@ -197,7 +200,7 @@ FTPInputStream::getPosition( osl::MutexGuard aGuard(m_aMutex); if(!m_tmpfl) throw IOException(); - + // fpos_t pos; // fgetpos(m_tmpfl,&pos); long pos; @@ -207,11 +210,11 @@ FTPInputStream::getPosition( -sal_Int64 SAL_CALL FTPInputStream::getLength( - void +sal_Int64 SAL_CALL FTPInputStream::getLength( + void ) throw( IOException,RuntimeException ) { - return m_nLength; + return m_nLength; } |