Kaydet (Commit) dcdc8df2 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

osl_getVolumeInformation: only stat if necessary

...in the hope that that makes cid#706206 (TOCTOU) go away

Change-Id: I4bc7b44e0268cf5d46aaf55fb4073dcdf67b324c
üst bf95b785
......@@ -211,16 +211,24 @@ oslFileError osl_getVolumeInformation( rtl_uString* ustrDirectoryURL, oslVolumeI
static oslFileError osl_psz_getVolumeInformation (
const sal_Char* pszDirectory, oslVolumeInfo* pInfo, sal_uInt32 uFieldMask)
{
__OSL_STATFS_STRUCT sfs;
if (!pInfo)
return osl_File_E_INVAL;
__OSL_STATFS_INIT(sfs);
pInfo->uValidFields = 0;
pInfo->uAttributes = 0;
pInfo->uTotalSpace = 0;
pInfo->uFreeSpace = 0;
pInfo->uUsedSpace = 0;
if ((uFieldMask
& (osl_VolumeInfo_Mask_Attributes | osl_VolumeInfo_Mask_TotalSpace
| osl_VolumeInfo_Mask_UsedSpace | osl_VolumeInfo_Mask_FreeSpace
| osl_VolumeInfo_Mask_FileSystemName
| osl_VolumeInfo_Mask_FileSystemCaseHandling))
!= 0)
{
__OSL_STATFS_STRUCT sfs;
__OSL_STATFS_INIT(sfs);
if ((__OSL_STATFS(pszDirectory, &sfs)) < 0)
{
oslFileError result = oslTranslateFileError(OSL_FET_ERROR, errno);
......@@ -247,10 +255,6 @@ static oslFileError osl_psz_getVolumeInformation (
pInfo->uValidFields |= osl_VolumeInfo_Mask_Attributes;
}
pInfo->uTotalSpace = 0;
pInfo->uFreeSpace = 0;
pInfo->uUsedSpace = 0;
#if defined(__OSL_STATFS_BLKSIZ)
if ((uFieldMask & osl_VolumeInfo_Mask_TotalSpace) ||
......@@ -274,8 +278,6 @@ static oslFileError osl_psz_getVolumeInformation (
pInfo->uValidFields |= osl_VolumeInfo_Mask_FreeSpace;
}
#endif /* __OSL_STATFS_BLKSIZ */
if ((pInfo->uValidFields & osl_VolumeInfo_Mask_TotalSpace) &&
(pInfo->uValidFields & osl_VolumeInfo_Mask_FreeSpace ))
{
......@@ -283,6 +285,26 @@ static oslFileError osl_psz_getVolumeInformation (
pInfo->uValidFields |= osl_VolumeInfo_Mask_UsedSpace;
}
#endif /* __OSL_STATFS_BLKSIZ */
#if defined(__OSL_STATFS_TYPENAME)
if (uFieldMask & osl_VolumeInfo_Mask_FileSystemName)
{
rtl_string2UString(
&(pInfo->ustrFileSystemName),
__OSL_STATFS_TYPENAME(sfs),
rtl_str_getLength(__OSL_STATFS_TYPENAME(sfs)),
osl_getThreadTextEncoding(),
OUSTRING_TO_OSTRING_CVTFLAGS);
OSL_ASSERT(pInfo->ustrFileSystemName != 0);
pInfo->uValidFields |= osl_VolumeInfo_Mask_FileSystemName;
}
#endif /* __OSL_STATFS_TYPENAME */
}
pInfo->uMaxNameLength = 0;
if (uFieldMask & osl_VolumeInfo_Mask_MaxNameLength)
{
......@@ -305,23 +327,6 @@ static oslFileError osl_psz_getVolumeInformation (
}
}
#if defined(__OSL_STATFS_TYPENAME)
if (uFieldMask & osl_VolumeInfo_Mask_FileSystemName)
{
rtl_string2UString(
&(pInfo->ustrFileSystemName),
__OSL_STATFS_TYPENAME(sfs),
rtl_str_getLength(__OSL_STATFS_TYPENAME(sfs)),
osl_getThreadTextEncoding(),
OUSTRING_TO_OSTRING_CVTFLAGS);
OSL_ASSERT(pInfo->ustrFileSystemName != 0);
pInfo->uValidFields |= osl_VolumeInfo_Mask_FileSystemName;
}
#endif /* __OSL_STATFS_TYPENAME */
return osl_File_E_None;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment