[Libreoffice-commits] core.git: sal/osl
Stephan Bergmann
sbergman at redhat.com
Wed Oct 25 15:17:11 UTC 2017
sal/osl/unx/file.cxx | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
New commits:
commit e5a5369030ef8a1619529a3058ed469cb973b558
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Wed Oct 25 17:15:37 2017 +0200
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
diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx
index d2bfc34ee3a5..b1383c2d0f9c 100644
--- a/sal/osl/unx/file.cxx
+++ b/sal/osl/unx/file.cxx
@@ -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();
More information about the Libreoffice-commits
mailing list