Skip to content

Commit e2904d3

Browse files
committed
[NDIS] NdisOpenFile: read file contents into buffer when opening it
NdisMapFile now returns a non-null buffer. CORE-20259
1 parent d72bcb1 commit e2904d3

File tree

1 file changed

+29
-0
lines changed
  • drivers/network/ndis/ndis

1 file changed

+29
-0
lines changed

drivers/network/ndis/ndis/misc.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ NdisCloseFile(
207207

208208
if ( FileHandleObject->Mapped )
209209
NdisUnmapFile ( FileHandle );
210+
if ( FileHandleObject->MapBuffer )
211+
ExFreePool ( FileHandleObject->MapBuffer );
210212

211213
ZwClose ( FileHandleObject->FileHandle );
212214

@@ -321,6 +323,31 @@ NdisOpenFile(
321323
}
322324
NtFileLength = StandardInfo.EndOfFile.LowPart;
323325

326+
FileHandleObject->MapBuffer = ExAllocatePool( NonPagedPool, NtFileLength );
327+
if (!FileHandleObject->MapBuffer)
328+
{
329+
NDIS_DbgPrint(MIN_TRACE, ("ExAllocatePool failed Name %wZ\n", FileName));
330+
*Status = NDIS_STATUS_ERROR_READING_FILE;
331+
goto cleanup;
332+
}
333+
334+
NtStatus = ZwReadFile(
335+
NtFileHandle,
336+
NULL,
337+
NULL,
338+
NULL,
339+
&IoStatusBlock,
340+
FileHandleObject->MapBuffer,
341+
NtFileLength,
342+
NULL,
343+
NULL);
344+
if ( !NT_SUCCESS(NtStatus) || IoStatusBlock.Information != NtFileLength )
345+
{
346+
NDIS_DbgPrint(MIN_TRACE, ("ZwReadFile failed (%x) Name %wZ\n", NtStatus, FileName));
347+
*Status = NDIS_STATUS_ERROR_READING_FILE;
348+
goto cleanup;
349+
}
350+
324351
cleanup:
325352
if ( FullFileName.Buffer != NULL )
326353
{
@@ -331,6 +358,8 @@ NdisOpenFile(
331358
{
332359
if ( FileHandleObject )
333360
{
361+
if ( FileHandleObject->MapBuffer )
362+
ExFreePool( FileHandleObject->MapBuffer );
334363
ExFreePool ( FileHandleObject );
335364
}
336365
*FileHandle = NULL;

0 commit comments

Comments
 (0)