mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-20 05:08:21 +08:00
mdbx: avoid on-stack allocation/chkstk inside mdbx_check4nonlocal().
6 of 17 for https://github.com/leo-yuriev/libmdbx/issues/43 Change-Id: Ib55a27c4859ff25e5b779a4514cd2e625ab99013
This commit is contained in:
parent
aa64597e8b
commit
ae2875e248
39
src/osal.c
39
src/osal.c
@ -817,26 +817,40 @@ int mdbx_check4nonlocal(mdbx_filehandle_t handle, int flags) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mdbx_GetVolumeInformationByHandleW && mdbx_GetFinalPathNameByHandleW) {
|
if (mdbx_GetVolumeInformationByHandleW && mdbx_GetFinalPathNameByHandleW) {
|
||||||
WCHAR PathBuffer[INT16_MAX];
|
WCHAR *PathBuffer = mdbx_malloc(sizeof(WCHAR) * INT16_MAX);
|
||||||
|
if (!PathBuffer)
|
||||||
|
return MDBX_ENOMEM;
|
||||||
|
|
||||||
|
int rc = MDBX_SUCCESS;
|
||||||
DWORD VolumeSerialNumber, FileSystemFlags;
|
DWORD VolumeSerialNumber, FileSystemFlags;
|
||||||
if (!mdbx_GetVolumeInformationByHandleW(handle, PathBuffer, INT16_MAX,
|
if (!mdbx_GetVolumeInformationByHandleW(handle, PathBuffer, INT16_MAX,
|
||||||
&VolumeSerialNumber, NULL,
|
&VolumeSerialNumber, NULL,
|
||||||
&FileSystemFlags, NULL, 0))
|
&FileSystemFlags, NULL, 0)) {
|
||||||
return GetLastError();
|
rc = GetLastError();
|
||||||
|
goto bailout;
|
||||||
|
}
|
||||||
|
|
||||||
if ((flags & MDBX_RDONLY) == 0) {
|
if ((flags & MDBX_RDONLY) == 0) {
|
||||||
if (FileSystemFlags & (FILE_SEQUENTIAL_WRITE_ONCE |
|
if (FileSystemFlags &
|
||||||
FILE_READ_ONLY_VOLUME | FILE_VOLUME_IS_COMPRESSED))
|
(FILE_SEQUENTIAL_WRITE_ONCE | FILE_READ_ONLY_VOLUME |
|
||||||
return ERROR_REMOTE_STORAGE_MEDIA_ERROR;
|
FILE_VOLUME_IS_COMPRESSED)) {
|
||||||
|
rc = ERROR_REMOTE_STORAGE_MEDIA_ERROR;
|
||||||
|
goto bailout;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mdbx_GetFinalPathNameByHandleW(handle, PathBuffer, INT16_MAX,
|
if (!mdbx_GetFinalPathNameByHandleW(handle, PathBuffer, INT16_MAX,
|
||||||
FILE_NAME_NORMALIZED | VOLUME_NAME_NT))
|
FILE_NAME_NORMALIZED |
|
||||||
return GetLastError();
|
VOLUME_NAME_NT)) {
|
||||||
|
rc = GetLastError();
|
||||||
|
goto bailout;
|
||||||
|
}
|
||||||
|
|
||||||
if (_wcsnicmp(PathBuffer, L"\\Device\\Mup\\", 12) == 0) {
|
if (_wcsnicmp(PathBuffer, L"\\Device\\Mup\\", 12) == 0) {
|
||||||
if (!(flags & MDBX_EXCLUSIVE))
|
if (!(flags & MDBX_EXCLUSIVE)) {
|
||||||
return ERROR_REMOTE_STORAGE_MEDIA_ERROR;
|
rc = ERROR_REMOTE_STORAGE_MEDIA_ERROR;
|
||||||
|
goto bailout;
|
||||||
|
}
|
||||||
} else if (mdbx_GetFinalPathNameByHandleW(handle, PathBuffer, INT16_MAX,
|
} else if (mdbx_GetFinalPathNameByHandleW(handle, PathBuffer, INT16_MAX,
|
||||||
FILE_NAME_NORMALIZED |
|
FILE_NAME_NORMALIZED |
|
||||||
VOLUME_NAME_DOS)) {
|
VOLUME_NAME_DOS)) {
|
||||||
@ -857,7 +871,7 @@ int mdbx_check4nonlocal(mdbx_filehandle_t handle, int flags) {
|
|||||||
case DRIVE_REMOTE:
|
case DRIVE_REMOTE:
|
||||||
default:
|
default:
|
||||||
if (!(flags & MDBX_EXCLUSIVE))
|
if (!(flags & MDBX_EXCLUSIVE))
|
||||||
return ERROR_REMOTE_STORAGE_MEDIA_ERROR;
|
rc = ERROR_REMOTE_STORAGE_MEDIA_ERROR;
|
||||||
// fall through
|
// fall through
|
||||||
case DRIVE_REMOVABLE:
|
case DRIVE_REMOVABLE:
|
||||||
case DRIVE_FIXED:
|
case DRIVE_FIXED:
|
||||||
@ -865,6 +879,9 @@ int mdbx_check4nonlocal(mdbx_filehandle_t handle, int flags) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bailout:
|
||||||
|
mdbx_free(PathBuffer);
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
(void)handle;
|
(void)handle;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user