Also check whether negative uOffset exceeds std::numeric_limits<off_t>::min()

...in the one case where uOffset is of signed type sal_Int64

Change-Id: I626f747f70fb720bcc5a4ee10fbce30fc0673ae9
This commit is contained in:
Stephan Bergmann 2017-10-25 17:15:37 +02:00
parent dc3ff192f3
commit e5a5369030

View file

@ -1147,8 +1147,12 @@ oslFileError SAL_CALL osl_syncFile(oslFileHandle Handle)
const off_t MAX_OFF_T = std::numeric_limits< off_t >::max();
namespace {
//coverity[result_independent_of_operands]
template<typename T> bool exceedsOffT(T n) { return n > MAX_OFF_T; }
template<typename T> bool exceedsMaxOffT(T n) { return n > MAX_OFF_T; }
template<typename T> bool exceedsMinOffT(T n)
{ return n < std::numeric_limits<off_t>::min(); }
}
@ -1172,7 +1176,7 @@ oslFileError SAL_CALL osl_mapFile(
size_t const nLength = sal::static_int_cast< size_t >(uLength);
if (exceedsOffT(uOffset))
if (exceedsMaxOffT(uOffset))
return osl_File_E_OVERFLOW;
if (pImpl->m_kind == FileHandle_Impl::KIND_MEM)
@ -1376,7 +1380,7 @@ oslFileError SAL_CALL osl_readFileAt(
if ((pImpl->m_state & FileHandle_Impl::STATE_SEEKABLE) == 0)
return osl_File_E_SPIPE;
if (exceedsOffT(uOffset))
if (exceedsMaxOffT(uOffset))
return osl_File_E_OVERFLOW;
off_t const nOffset = sal::static_int_cast< off_t >(uOffset);
@ -1411,7 +1415,7 @@ oslFileError SAL_CALL osl_writeFileAt(
if ((pImpl->m_state & FileHandle_Impl::STATE_WRITEABLE) == 0)
return osl_File_E_BADF;
if (exceedsOffT(uOffset))
if (exceedsMaxOffT(uOffset))
return osl_File_E_OVERFLOW;
off_t const nOffset = sal::static_int_cast< off_t >(uOffset);
@ -1461,7 +1465,7 @@ oslFileError SAL_CALL osl_setFilePos(oslFileHandle Handle, sal_uInt32 uHow, sal_
if ((!pImpl) || ((pImpl->m_kind == FileHandle_Impl::KIND_FD) && (pImpl->m_fd == -1)))
return osl_File_E_INVAL;
if (exceedsOffT(uOffset))
if (exceedsMaxOffT(uOffset) || exceedsMinOffT(uOffset))
return osl_File_E_OVERFLOW;
off_t nPos = 0, nOffset = sal::static_int_cast< off_t >(uOffset);
@ -1524,7 +1528,7 @@ oslFileError SAL_CALL osl_setFileSize(oslFileHandle Handle, sal_uInt64 uSize)
if ((pImpl->m_state & FileHandle_Impl::STATE_WRITEABLE) == 0)
return osl_File_E_BADF;
if (exceedsOffT(uSize))
if (exceedsMaxOffT(uSize))
return osl_File_E_OVERFLOW;
oslFileError result = pImpl->syncFile();