@@ -1050,7 +1050,7 @@ DLLEXPORT NTSTATUS WINAPI usvfs::hook_NtQueryObject(
1050
1050
HANDLE Handle, OBJECT_INFORMATION_CLASS ObjectInformationClass,
1051
1051
PVOID ObjectInformation, ULONG ObjectInformationLength, PULONG ReturnLength)
1052
1052
{
1053
- NTSTATUS res;
1053
+ NTSTATUS res = STATUS_SUCCESS ;
1054
1054
1055
1055
HOOK_START_GROUP (MutExHookGroup::FILE_ATTRIBUTES)
1056
1056
if (!callContext.active ()) {
@@ -1091,7 +1091,7 @@ DLLEXPORT NTSTATUS WINAPI usvfs::hook_NtQueryObject(
1091
1091
std::wstring buffer (static_cast <LPCWSTR>(trackerInfo));
1092
1092
buffer[6 ] = L' \0 ' ;
1093
1093
1094
- const auto charCount = QueryDosDeviceW (buffer.data () + 4 , deviceName, ARRAYSIZE (deviceName));
1094
+ QueryDosDeviceW (buffer.data () + 4 , deviceName, ARRAYSIZE (deviceName));
1095
1095
1096
1096
buffer =
1097
1097
std::wstring (deviceName) + L' \\ ' + std::wstring (buffer.data () + 7 , buffer.size () - 7 );
@@ -1107,25 +1107,26 @@ DLLEXPORT NTSTATUS WINAPI usvfs::hook_NtQueryObject(
1107
1107
}
1108
1108
1109
1109
if (ReturnLength) {
1110
- *ReturnLength = requiredLength;
1110
+ *ReturnLength = static_cast <ULONG>( requiredLength) ;
1111
1111
}
1112
1112
} else {
1113
1113
// put the unicode buffer at the end of the object
1114
- const auto unicodeBufferLength =
1115
- ObjectInformationLength - sizeof (OBJECT_NAME_INFORMATION);
1114
+ const USHORT unicodeBufferLength = static_cast <USHORT>(std::min (
1115
+ static_cast <unsigned long long >(std::numeric_limits<USHORT>::max ()),
1116
+ static_cast <unsigned long long >(ObjectInformationLength - sizeof (OBJECT_NAME_INFORMATION))));
1116
1117
LPWSTR unicodeBuffer = reinterpret_cast <LPWSTR>(
1117
1118
static_cast <LPSTR>(ObjectInformation) + sizeof (OBJECT_NAME_INFORMATION));
1118
1119
1119
1120
// copy the path into the buffer
1120
- wmemcpy (unicodeBuffer, buffer.data (), buffer.size ());
1121
+ wmemcpy_s (unicodeBuffer, unicodeBufferLength , buffer.data (), buffer.size ());
1121
1122
1122
1123
// set the null character
1123
1124
unicodeBuffer[buffer.size ()] = L' \0 ' ;
1124
1125
1125
1126
// update the actual unicode string
1126
1127
info->Name .Buffer = unicodeBuffer;
1127
1128
info->Name .Length = static_cast <USHORT>(buffer.size () * 2 );
1128
- info->Name .MaximumLength = static_cast <USHORT>( unicodeBufferLength) ;
1129
+ info->Name .MaximumLength = unicodeBufferLength;
1129
1130
1130
1131
res = STATUS_SUCCESS;
1131
1132
}
@@ -1156,7 +1157,7 @@ DLLEXPORT NTSTATUS WINAPI usvfs::hook_NtQueryInformationFile(
1156
1157
HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FileInformation,
1157
1158
ULONG Length, FILE_INFORMATION_CLASS FileInformationClass)
1158
1159
{
1159
- NTSTATUS res;
1160
+ NTSTATUS res = STATUS_SUCCESS ;
1160
1161
1161
1162
HOOK_START_GROUP (MutExHookGroup::FILE_ATTRIBUTES)
1162
1163
if (!callContext.active ()) {
@@ -1217,7 +1218,7 @@ DLLEXPORT NTSTATUS WINAPI usvfs::hook_NtQueryInformationFile(
1217
1218
1218
1219
// not using SetInfoFilename because the length is not set and we do not need to
1219
1220
// 0-out the memory here
1220
- info->FileNameLength = ( trackerInfo.size () - 6 ) * 2 ;
1221
+ info->FileNameLength = static_cast <ULONG>(( trackerInfo.size () - 6 ) * 2 ) ;
1221
1222
wmemcpy (info->FileName , filenameFixed, trackerInfo.size () - 6 );
1222
1223
res = STATUS_SUCCESS;
1223
1224
0 commit comments