diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2017-10-25 17:15:37 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2017-10-25 17:15:37 +0200 |
commit | e5a5369030ef8a1619529a3058ed469cb973b558 (patch) | |
tree | 0650ed013f93d913c0b310f2efbe469f780d1409 /sal | |
parent | dc3ff192f3f048059cf149f416d0b237eb33b014 (diff) |
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
Diffstat (limited to 'sal')
-rw-r--r-- | sal/osl/unx/file.cxx | 16 |
1 files changed, 10 insertions, 6 deletions
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(); |