Skip to content

Commit b8d3abc

Browse files
authored
Replaced ExAllocatePoolWithTag to more secure ExAllocatePoolZero in samples of filesystems and filesystem filters; made necessary changes to make solutions buildable under recent Visual Studio (#725)
1 parent ca1f038 commit b8d3abc

34 files changed

Lines changed: 1275 additions & 1269 deletions

filesys/cdfs/cdprocs.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,12 @@ CdVerifyOrCreateDirStreamFile (
231231
//
232232
// Unsafe test to see if call / lock neccessary.
233233
//
234-
234+
235235
if (NULL == Fcb->FileObject) {
236-
236+
237237
CdCreateInternalStream( IrpContext,
238238
Fcb->Vcb,
239-
Fcb,
239+
Fcb,
240240
&Fcb->FileNamePrefix.ExactCaseName.FileName);
241241
}
242242
}
@@ -371,8 +371,8 @@ CdHijackIrpAndFlushDevice (
371371
if (NULL == *(UB)) { \
372372
CdRaiseStatus( (IC), STATUS_INSUFFICIENT_RESOURCES); \
373373
} \
374-
}
375-
374+
}
375+
376376

377377
#define CdLockUserBuffer(IC,BL,OP) { \
378378
if ((IC)->Irp->MdlAddress == NULL) { \
@@ -809,7 +809,7 @@ CdFindPrefix (
809809
//
810810

811811
typedef enum _TYPE_OF_ACQUIRE {
812-
812+
813813
AcquireExclusive,
814814
AcquireShared,
815815
AcquireSharedStarveExclusive
@@ -944,10 +944,10 @@ CdAcquireResource (
944944

945945
#define CdAcquireCacheForRead( IC) \
946946
ExAcquireResourceSharedLite( &(IC)->Vcb->SectorCacheResource, TRUE)
947-
947+
948948
#define CdAcquireCacheForUpdate( IC) \
949949
ExAcquireResourceExclusiveLite( &(IC)->Vcb->SectorCacheResource, TRUE)
950-
950+
951951
#define CdReleaseCache( IC) \
952952
ExReleaseResourceLite( &(IC)->Vcb->SectorCacheResource);
953953

@@ -1225,7 +1225,7 @@ CdInitializeStackIrpContext (
12251225
//
12261226

12271227
#define CdCreateIrpContextLite(IC) \
1228-
ExAllocatePoolWithTag( CdNonPagedPool, sizeof( IRP_CONTEXT_LITE ), TAG_IRP_CONTEXT_LITE )
1228+
ExAllocatePoolZero( CdNonPagedPool, sizeof( IRP_CONTEXT_LITE ), TAG_IRP_CONTEXT_LITE )
12291229

12301230
#define CdFreeIrpContextLite(ICL) \
12311231
CdFreePool( &(ICL) )
@@ -1372,7 +1372,7 @@ CdOperationIsDasdOpen (
13721372
)
13731373
{
13741374
PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation( IrpContext->Irp);
1375-
1375+
13761376
return ((IrpContext->MajorFunction == IRP_MJ_CREATE) &&
13771377
(IrpSp->FileObject->FileName.Length == 0) &&
13781378
(IrpSp->FileObject->RelatedFileObject == NULL));
@@ -1427,7 +1427,7 @@ CdDismountVcb (
14271427
#define CdUpdateVcbCondition( V, C) (V)->VcbCondition = (C)
14281428

14291429
#define CdMarkRealDevForVerify( DO) SetFlag( (DO)->Flags, DO_VERIFY_VOLUME)
1430-
1430+
14311431
#define CdMarkRealDevVerifyOk( DO) ClearFlag( (DO)->Flags, DO_VERIFY_VOLUME)
14321432

14331433

@@ -1577,7 +1577,7 @@ CdOplockComplete (
15771577

15781578
INLINE
15791579
ULONG
1580-
SectorsFromLlBytes(
1580+
SectorsFromLlBytes(
15811581
ULONGLONG Bytes
15821582
) {
15831583

filesys/cdfs/prefxsup.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,11 @@ Return Value:
106106

107107
if (Fcb->ShortNamePrefix == NULL) {
108108

109-
Fcb->ShortNamePrefix = ExAllocatePoolWithTag( CdPagedPool,
110-
sizeof( PREFIX_ENTRY ),
111-
TAG_PREFIX_ENTRY );
109+
Fcb->ShortNamePrefix = ExAllocatePoolZero( CdPagedPool,
110+
sizeof( PREFIX_ENTRY ),
111+
TAG_PREFIX_ENTRY );
112112

113113
if (Fcb->ShortNamePrefix == NULL) { return; }
114-
115-
RtlZeroMemory( Fcb->ShortNamePrefix, sizeof( PREFIX_ENTRY ));
116114
}
117115

118116
PrefixEntry = Fcb->ShortNamePrefix;
@@ -151,9 +149,9 @@ Return Value:
151149

152150
if (Name->FileName.Length > BYTE_COUNT_EMBEDDED_NAME) {
153151

154-
NameBuffer = ExAllocatePoolWithTag( CdPagedPool,
155-
Name->FileName.Length * 2,
156-
TAG_PREFIX_NAME );
152+
NameBuffer = ExAllocatePoolZero( CdPagedPool,
153+
Name->FileName.Length * 2,
154+
TAG_PREFIX_NAME );
157155

158156
//
159157
// Exit if no name buffer.
@@ -228,9 +226,9 @@ Return Value:
228226

229227
{
230228
PAGED_CODE();
231-
229+
232230
UNREFERENCED_PARAMETER( IrpContext );
233-
231+
234232
//
235233
// Start with the short name prefix entry.
236234
//

filesys/cdfs/strucsup.c

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Module Name:
8585
CdFreePool( &(F) )
8686

8787
#define CdAllocateFcbNonpaged(IC) \
88-
ExAllocatePoolWithTag( CdNonPagedPool, sizeof( FCB_NONPAGED ), TAG_FCB_NONPAGED )
88+
ExAllocatePoolZero( CdNonPagedPool, sizeof( FCB_NONPAGED ), TAG_FCB_NONPAGED )
8989

9090
#define CdDeallocateFcbNonpaged(IC,FNP) \
9191
CdFreePool( &(FNP) )
@@ -311,13 +311,13 @@ Return Value:
311311

312312
InitializeListHead( &Vcb->DirNotifyList );
313313
FsRtlNotifyInitializeSync( &Vcb->NotifySync );
314-
314+
315315
//
316316
// Pick up a VPB right now so we know we can pull this filesystem stack
317-
// off of the storage stack on demand. This can raise - if it does,
317+
// off of the storage stack on demand. This can raise - if it does,
318318
// uninitialize the notify structures before returning.
319319
//
320-
320+
321321
try {
322322

323323
Vcb->SwapVpb = FsRtlAllocatePoolWithTag( CdNonPagedPool,
@@ -327,7 +327,7 @@ Return Value:
327327
finally {
328328

329329
if (AbnormalTermination()) {
330-
330+
331331
FsRtlNotifyUninitializeSync( &Vcb->NotifySync );
332332
}
333333
}
@@ -337,7 +337,7 @@ Return Value:
337337
//
338338

339339
RtlZeroMemory( Vcb->SwapVpb, sizeof( VPB ) );
340-
340+
341341
//
342342
// Initialize the resource variable for the Vcb and files.
343343
//
@@ -493,7 +493,7 @@ Return Value:
493493
//
494494
// We no longer accept media where blocksize != sector size.
495495
//
496-
496+
497497
if (Vcb->BlockSize != SECTOR_SIZE) {
498498

499499
CdRaiseStatus( IrpContext, STATUS_DISK_CORRUPT_ERROR );
@@ -502,7 +502,7 @@ Return Value:
502502
Vcb->BlocksPerSector = SECTOR_SIZE / Vcb->BlockSize;
503503
Vcb->BlockMask = Vcb->BlockSize - 1;
504504
Vcb->BlockInverseMask = ~Vcb->BlockMask;
505-
505+
506506
Vcb->BlockToSectorShift = 0;
507507
Vcb->BlockToByteShift = SECTOR_SHIFT;
508508

@@ -656,16 +656,16 @@ Return Value:
656656

657657
McbEntry = Vcb->VolumeDasdFcb->Mcb.McbArray;
658658

659-
McbEntry->FileOffset =
659+
McbEntry->FileOffset =
660660
McbEntry->DiskOffset = 0;
661-
661+
662662
McbEntry->ByteCount = Vcb->VolumeDasdFcb->AllocationSize.QuadPart;
663-
663+
664664
McbEntry->DataBlockByteCount =
665665
McbEntry->TotalBlockByteCount = McbEntry->ByteCount;
666-
666+
667667
Vcb->VolumeDasdFcb->Mcb.CurrentEntryCount = 1;
668-
668+
669669
CdUnlockFcb( IrpContext, Vcb->VolumeDasdFcb );
670670

671671
//
@@ -861,7 +861,7 @@ Return Value:
861861

862862
SetFlag( Vcb->VcbState, VCB_STATE_ISO );
863863
}
864-
864+
865865
} finally {
866866

867867
if (UnlockVcb) { CdUnlockVcb( IrpContext, Vcb ); }
@@ -898,15 +898,15 @@ Return Value:
898898

899899
ASSERT_EXCLUSIVE_CDDATA;
900900
ASSERT_EXCLUSIVE_VCB( Vcb );
901-
901+
902902
UNREFERENCED_PARAMETER( IrpContext );
903-
903+
904904
//
905905
// Chuck the backpocket Vpb we kept just in case.
906906
//
907907

908908
CdFreePool( &Vcb->SwapVpb );
909-
909+
910910
//
911911
// If there is a Vpb then we must delete it ourselves.
912912
//
@@ -918,7 +918,7 @@ Return Value:
918918
//
919919

920920
if (Vcb->TargetDeviceObject != NULL) {
921-
921+
922922
ObDereferenceObject( Vcb->TargetDeviceObject );
923923
}
924924

@@ -1069,7 +1069,7 @@ Return Value:
10691069

10701070
default:
10711071

1072-
#pragma prefast( suppress: __WARNING_USE_OTHER_FUNCTION, "This is a bug." )
1072+
#pragma prefast( suppress: __WARNING_USE_OTHER_FUNCTION, "This is a bug." )
10731073
CdBugCheck( 0, 0, 0 );
10741074
}
10751075

@@ -1108,7 +1108,7 @@ Return Value:
11081108
//
11091109

11101110
ExInitializeFastMutex( &NewFcb->FcbNonpaged->AdvancedFcbHeaderMutex );
1111-
FsRtlSetupAdvancedHeader( &NewFcb->Header,
1111+
FsRtlSetupAdvancedHeader( &NewFcb->Header,
11121112
&NewFcb->FcbNonpaged->AdvancedFcbHeaderMutex );
11131113

11141114
if (NodeTypeCode == CDFS_NTC_FCB_DATA) {
@@ -1424,7 +1424,7 @@ Return Value:
14241424
PAGED_CODE();
14251425

14261426
UNREFERENCED_PARAMETER( IrpContext );
1427-
1427+
14281428
//
14291429
// Allocate and initialize the structure.
14301430
//
@@ -1476,7 +1476,7 @@ Return Value:
14761476
PAGED_CODE();
14771477

14781478
UNREFERENCED_PARAMETER( IrpContext );
1479-
1479+
14801480
if (Ccb->SearchExpression.FileName.Buffer != NULL) {
14811481

14821482
CdFreePool( &Ccb->SearchExpression.FileName.Buffer );
@@ -1547,7 +1547,7 @@ Return Value:
15471547
//
15481548

15491549
if (FileLock == NULL) {
1550-
1550+
15511551
if (RaiseOnError) {
15521552

15531553
NT_ASSERT( ARGUMENT_PRESENT( IrpContext ));
@@ -1611,11 +1611,11 @@ Return Value:
16111611
}
16121612

16131613
NT_ASSERT( IrpSp->FileObject != NULL ||
1614-
1614+
16151615
(IrpSp->MajorFunction == IRP_MJ_FILE_SYSTEM_CONTROL &&
16161616
IrpSp->MinorFunction == IRP_MN_USER_FS_REQUEST &&
16171617
IrpSp->Parameters.FileSystemControl.FsControlCode == FSCTL_INVALIDATE_VOLUMES) ||
1618-
1618+
16191619
(IrpSp->MajorFunction == IRP_MJ_FILE_SYSTEM_CONTROL &&
16201620
IrpSp->MinorFunction == IRP_MN_MOUNT_VOLUME ) ||
16211621

@@ -1681,7 +1681,7 @@ Return Value:
16811681
if (IrpSp->DeviceObject != CdData.FileSystemDeviceObject) {
16821682

16831683
NewIrpContext->Vcb = &((PVOLUME_DEVICE_OBJECT) IrpSp->DeviceObject)->Vcb;
1684-
1684+
16851685
}
16861686

16871687
//
@@ -2168,7 +2168,7 @@ Return Value:
21682168
PAGED_CODE();
21692169

21702170
UNREFERENCED_PARAMETER( IrpContext );
2171-
2171+
21722172
Fcb = (PFCB) RtlEnumerateGenericTableWithoutSplaying( &Vcb->FcbTable, RestartKey );
21732173

21742174
if (Fcb != NULL) {
@@ -2243,7 +2243,7 @@ Return Value:
22432243
// Zero the command block. This conveniently corresponds to an
22442244
// LBA mode READ_TOC request.
22452245
//
2246-
2246+
22472247
RtlZeroMemory( &Command, sizeof( Command));
22482248

22492249
RetryReadToc:
@@ -2343,7 +2343,7 @@ Return Value:
23432343
// Knock 2.5 minutes off the current track to hide the final leadin.
23442344
// 2.5 min = 150 sec = (x 75) 11250 frames (sectors).
23452345
//
2346-
2346+
23472347
SwapCopyUchar4( &Address, &Track->Address);
23482348
Address -= 11250;
23492349
SwapCopyUchar4( &Track->Address, &Address);
@@ -2557,9 +2557,9 @@ Return Value:
25572557
PFCB_NONPAGED FcbNonpaged;
25582558

25592559
PAGED_CODE();
2560-
2560+
25612561
UNREFERENCED_PARAMETER( IrpContext );
2562-
2562+
25632563
//
25642564
// Allocate the non-paged pool and initialize the various
25652565
// synchronization objects.
@@ -2610,9 +2610,9 @@ Return Value:
26102610

26112611
{
26122612
PAGED_CODE();
2613-
2613+
26142614
UNREFERENCED_PARAMETER( IrpContext );
2615-
2615+
26162616
ExDeleteResourceLite( &FcbNonpaged->FcbResource );
26172617

26182618
CdDeallocateFcbNonpaged( IrpContext, FcbNonpaged );
@@ -2708,7 +2708,7 @@ Return Value:
27082708

27092709
{
27102710
PAGED_CODE();
2711-
2711+
27122712
UNREFERENCED_PARAMETER( FcbTable );
27132713

27142714
return( FsRtlAllocatePoolWithTag( CdPagedPool, ByteSize, TAG_FCB_TABLE ));
@@ -2793,7 +2793,7 @@ Return Value:
27932793
PAGED_CODE();
27942794

27952795
UNREFERENCED_PARAMETER( IrpContext );
2796-
2796+
27972797
//
27982798
// Check if there are two tracks or fewer.
27992799
//
@@ -2813,10 +2813,10 @@ Return Value:
28132813
//
28142814

28152815
while (ThisTrack != LastTrack) {
2816-
2816+
28172817
SwapCopyUchar4( &Address, ThisTrack->Address);
28182818
CdLbnToMmSsFf( Address, (PUCHAR)&MsfAddress);
2819-
2819+
28202820
SerialNumber += MsfAddress;
28212821
ThisTrack += 1;
28222822
}

0 commit comments

Comments
 (0)