From 872f363a5926c76ed8b21dc209352cebfe955764 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Mon, 15 Oct 2018 20:34:28 +0300 Subject: Avoid risk of looking at an errno modified by SAL_INFO() call Thanks to Stephan for noticing. Change-Id: I6b90258bdc6bce7b2aeb44f9a1a136b4b9bd51c9 Reviewed-on: https://gerrit.libreoffice.org/61812 Tested-by: Jenkins Reviewed-by: Tor Lillqvist --- sal/osl/unx/file.cxx | 7 +++++-- sal/osl/unx/file_misc.cxx | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'sal/osl/unx') diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx index c3c5cd7fd655..ae1bc31c9069 100644 --- a/sal/osl/unx/file.cxx +++ b/sal/osl/unx/file.cxx @@ -966,7 +966,10 @@ oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, sal_uI int e = errno; SAL_INFO("sal.file", "flock(" << fd << ",LOCK_EX|LOCK_NB): errno " << e << ": " << strerror(e)); /* Mac OSX returns ENOTSUP for webdav drives. We should try read lock */ - if ((e != ENOTSUP) || ((flock(fd, LOCK_SH | LOCK_NB) == 1) && (errno != ENOTSUP))) + + // Restore errno after possibly having been overwritten by the SAL_INFO above... + errno = e; + if ((errno != ENOTSUP) || ((flock(fd, LOCK_SH | LOCK_NB) == 1) && (errno != ENOTSUP))) { eRet = oslTranslateFileError(errno); (void) close(fd); @@ -1100,7 +1103,7 @@ oslFileError SAL_CALL osl_syncFile(oslFileHandle Handle) { int e = errno; SAL_INFO("sal.file", "fsync(" << pImpl->m_fd << "): errno " << e << ": " << strerror(e)); - return oslTranslateFileError(errno); + return oslTranslateFileError(e); } else SAL_INFO("sal.file", "fsync(" << pImpl->m_fd << "): OK"); diff --git a/sal/osl/unx/file_misc.cxx b/sal/osl/unx/file_misc.cxx index 507779c7fe6c..a45d32e4c79e 100644 --- a/sal/osl/unx/file_misc.cxx +++ b/sal/osl/unx/file_misc.cxx @@ -218,6 +218,8 @@ oslFileError SAL_CALL osl_openDirectory(rtl_uString* ustrDirectoryURL, oslDirect { int e = errno; SAL_INFO("sal.file", "opendir(" << path << "): errno " << e << ": " << strerror(e)); + // Restore errno after possible modification by SAL_INFO above + errno = e; } } } @@ -249,7 +251,7 @@ oslFileError SAL_CALL osl_closeDirectory(oslDirectory pDirectory) { int e = errno; SAL_INFO("sal.file", "closedir(" << pDirImpl->pDirStruct << "): errno " << e << ": " << strerror(e)); - err = oslTranslateFileError(errno); + err = oslTranslateFileError(e); } else SAL_INFO("sal.file", "closedir(" << pDirImpl->pDirStruct << "): OK"); @@ -819,7 +821,7 @@ static oslFileError oslDoCopy(const sal_Char* pszSourceFileName, const sal_Char* int e = errno; SAL_INFO("sal.file", "rename(" << pszDestFileName << ", " << tmpDestFile << "): errno " << e << ": " << strerror(e)); - if (errno == ENOENT) + if (e == ENOENT) { DestFileExists = 0; } -- cgit