Skip to content

Commit

Permalink
lib - Add DispatchGetEventInformationLength to ensure we send at leas…
Browse files Browse the repository at this point in the history
…t EVENT_INFORMATION buffer size.
  • Loading branch information
Liryna committed Apr 27, 2020
1 parent 5530a69 commit 435bc18
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion dokan/cleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ VOID DispatchCleanup(HANDLE Handle, PEVENT_CONTEXT EventContext,
PEVENT_INFORMATION eventInfo;
DOKAN_FILE_INFO fileInfo;
PDOKAN_OPEN_INFO openInfo;
ULONG sizeOfEventInfo = sizeof(EVENT_INFORMATION);
ULONG sizeOfEventInfo = DispatchGetEventInformationLength(0);

CheckFileName(EventContext->Operation.Cleanup.FileName);

Expand Down
2 changes: 1 addition & 1 deletion dokan/close.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ VOID DispatchClose(HANDLE Handle, PEVENT_CONTEXT EventContext,
PEVENT_INFORMATION eventInfo;
DOKAN_FILE_INFO fileInfo;
PDOKAN_OPEN_INFO openInfo;
ULONG sizeOfEventInfo = sizeof(EVENT_INFORMATION);
ULONG sizeOfEventInfo = DispatchGetEventInformationLength(0);

UNREFERENCED_PARAMETER(Handle);

Expand Down
5 changes: 2 additions & 3 deletions dokan/directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,9 @@ VOID DispatchDirectoryInformation(HANDLE Handle, PEVENT_CONTEXT EventContext,
PDOKAN_OPEN_INFO openInfo;
NTSTATUS status = STATUS_SUCCESS;
ULONG fileInfoClass = EventContext->Operation.Directory.FileInformationClass;
ULONG sizeOfEventInfo = sizeof(EVENT_INFORMATION) - 8 +
EventContext->Operation.Directory.BufferLength;

BOOLEAN patternCheck = TRUE;
ULONG sizeOfEventInfo = DispatchGetEventInformationLength(
EventContext->Operation.Directory.BufferLength);

CheckFileName(EventContext->Operation.Directory.DirectoryName);

Expand Down
8 changes: 8 additions & 0 deletions dokan/dokan.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,14 @@ VOID CheckFileName(LPWSTR FileName) {
FileName[len - 1] = '\0';
}

ULONG DispatchGetEventInformationLength(ULONG bufferSize) {
// EVENT_INFORMATION has a buffer of size 8 already
// we remote it to the struct size and add the requested buffer size
// but we need at least to have enough space to set EVENT_INFORMATION
return max((ULONG)sizeof(EVENT_INFORMATION),
FIELD_OFFSET(EVENT_INFORMATION, Buffer[0]) + bufferSize);
}

PEVENT_INFORMATION
DispatchCommon(PEVENT_CONTEXT EventContext, ULONG SizeOfEventInfo,
PDOKAN_INSTANCE DokanInstance, PDOKAN_FILE_INFO DokanFileInfo,
Expand Down
2 changes: 2 additions & 0 deletions dokan/dokani.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ BOOL IsMountPointDriveLetter(LPCWSTR mountPoint);
VOID SendEventInformation(HANDLE Handle, PEVENT_INFORMATION EventInfo,
ULONG EventLength, PDOKAN_INSTANCE DokanInstance);

ULONG DispatchGetEventInformationLength(ULONG bufferSize);

PEVENT_INFORMATION
DispatchCommon(PEVENT_CONTEXT EventContext, ULONG SizeOfEventInfo,
PDOKAN_INSTANCE DokanInstance, PDOKAN_FILE_INFO DokanFileInfo,
Expand Down
6 changes: 2 additions & 4 deletions dokan/fileinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,8 @@ VOID DispatchQueryInformation(HANDLE Handle, PEVENT_CONTEXT EventContext,
ULONG remainingLength;
NTSTATUS status = STATUS_INVALID_PARAMETER;
PDOKAN_OPEN_INFO openInfo;
ULONG sizeOfEventInfo;

sizeOfEventInfo =
sizeof(EVENT_INFORMATION) - 8 + EventContext->Operation.File.BufferLength;
ULONG sizeOfEventInfo = DispatchGetEventInformationLength(
EventContext->Operation.File.BufferLength);

CheckFileName(EventContext->Operation.File.FileName);

Expand Down
2 changes: 1 addition & 1 deletion dokan/flush.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ VOID DispatchFlush(HANDLE Handle, PEVENT_CONTEXT EventContext,
PDOKAN_INSTANCE DokanInstance) {
DOKAN_FILE_INFO fileInfo;
PEVENT_INFORMATION eventInfo;
ULONG sizeOfEventInfo = sizeof(EVENT_INFORMATION);
PDOKAN_OPEN_INFO openInfo;
NTSTATUS status;
ULONG sizeOfEventInfo = DispatchGetEventInformationLength(0);

CheckFileName(EventContext->Operation.Flush.FileName);

Expand Down
2 changes: 1 addition & 1 deletion dokan/lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ VOID DispatchLock(HANDLE Handle, PEVENT_CONTEXT EventContext,
PDOKAN_INSTANCE DokanInstance) {
DOKAN_FILE_INFO fileInfo;
PEVENT_INFORMATION eventInfo;
ULONG sizeOfEventInfo = sizeof(EVENT_INFORMATION);
PDOKAN_OPEN_INFO openInfo;
NTSTATUS status;
ULONG sizeOfEventInfo = DispatchGetEventInformationLength(0);

CheckFileName(EventContext->Operation.Lock.FileName);

Expand Down
6 changes: 2 additions & 4 deletions dokan/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ VOID DispatchRead(HANDLE Handle, PEVENT_CONTEXT EventContext,
ULONG readLength = 0;
NTSTATUS status = STATUS_NOT_IMPLEMENTED;
DOKAN_FILE_INFO fileInfo;
ULONG sizeOfEventInfo;

sizeOfEventInfo =
sizeof(EVENT_INFORMATION) - 8 + EventContext->Operation.Read.BufferLength;
ULONG sizeOfEventInfo = DispatchGetEventInformationLength(
EventContext->Operation.Read.BufferLength);

CheckFileName(EventContext->Operation.Read.FileName);

Expand Down
8 changes: 3 additions & 5 deletions dokan/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,11 @@ VOID DispatchQuerySecurity(HANDLE Handle, PEVENT_CONTEXT EventContext,
PEVENT_INFORMATION eventInfo;
DOKAN_FILE_INFO fileInfo;
PDOKAN_OPEN_INFO openInfo;
ULONG eventInfoLength;
NTSTATUS status = STATUS_NOT_IMPLEMENTED;
ULONG lengthNeeded = 0;
ULONG eventInfoLength = DispatchGetEventInformationLength(
EventContext->Operation.Security.BufferLength);

eventInfoLength = sizeof(EVENT_INFORMATION) - 8 +
EventContext->Operation.Security.BufferLength;
CheckFileName(EventContext->Operation.Security.FileName);

eventInfo = DispatchCommon(EventContext, eventInfoLength, DokanInstance,
Expand Down Expand Up @@ -184,11 +183,10 @@ VOID DispatchSetSecurity(HANDLE Handle, PEVENT_CONTEXT EventContext,
PEVENT_INFORMATION eventInfo;
DOKAN_FILE_INFO fileInfo;
PDOKAN_OPEN_INFO openInfo;
ULONG eventInfoLength;
NTSTATUS status = STATUS_NOT_IMPLEMENTED;
PSECURITY_DESCRIPTOR securityDescriptor;
ULONG eventInfoLength = DispatchGetEventInformationLength(0);

eventInfoLength = sizeof(EVENT_INFORMATION);
CheckFileName(EventContext->Operation.SetSecurity.FileName);

eventInfo = DispatchCommon(EventContext, eventInfoLength, DokanInstance,
Expand Down
5 changes: 3 additions & 2 deletions dokan/setfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,14 @@ VOID DispatchSetInformation(HANDLE Handle, PEVENT_CONTEXT EventContext,
PDOKAN_OPEN_INFO openInfo;
DOKAN_FILE_INFO fileInfo;
NTSTATUS status = STATUS_NOT_IMPLEMENTED;
ULONG sizeOfEventInfo = sizeof(EVENT_INFORMATION);
ULONG sizeOfEventInfo = DispatchGetEventInformationLength(0);

if (EventContext->Operation.SetFile.FileInformationClass == FileRenameInformation
|| EventContext->Operation.SetFile.FileInformationClass == FileRenameInformationEx) {
PDOKAN_RENAME_INFORMATION renameInfo = (PDOKAN_RENAME_INFORMATION)(
(PCHAR)EventContext + EventContext->Operation.SetFile.BufferOffset);
sizeOfEventInfo += renameInfo->FileNameLength;
sizeOfEventInfo =
DispatchGetEventInformationLength(renameInfo->FileNameLength);
}

CheckFileName(EventContext->Operation.SetFile.FileName);
Expand Down
4 changes: 2 additions & 2 deletions dokan/volume.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ VOID DispatchQueryVolumeInformation(HANDLE Handle, PEVENT_CONTEXT EventContext,
PEVENT_INFORMATION eventInfo;
DOKAN_FILE_INFO fileInfo;
PDOKAN_OPEN_INFO openInfo;
ULONG sizeOfEventInfo = sizeof(EVENT_INFORMATION) - 8 +
EventContext->Operation.Volume.BufferLength;
ULONG sizeOfEventInfo = DispatchGetEventInformationLength(
EventContext->Operation.Volume.BufferLength);

eventInfo = (PEVENT_INFORMATION)malloc(sizeOfEventInfo);
if (eventInfo == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion dokan/write.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ VOID DispatchWrite(HANDLE Handle, PEVENT_CONTEXT EventContext,
NTSTATUS status;
DOKAN_FILE_INFO fileInfo;
BOOL bufferAllocated = FALSE;
ULONG sizeOfEventInfo = sizeof(EVENT_INFORMATION);
ULONG returnedLength = 0;
BOOL SendWriteRequestStatus = TRUE; // otherwise DokanInstance->DokanOperations->WriteFile cannot be called
DWORD SendWriteRequestLastError = 0;
ULONG sizeOfEventInfo = DispatchGetEventInformationLength(0);

eventInfo = DispatchCommon(EventContext, sizeOfEventInfo, DokanInstance,
&fileInfo, &openInfo);
Expand Down

0 comments on commit 435bc18

Please sign in to comment.