diff --git a/src/dll/fsop.c b/src/dll/fsop.c index 7621e565..41e9d2e3 100644 --- a/src/dll/fsop.c +++ b/src/dll/fsop.c @@ -1805,19 +1805,14 @@ FSP_API NTSTATUS FspFileSystemEnumerateEa(FSP_FILE_SYSTEM *FileSystem, PVOID Context, PFILE_FULL_EA_INFORMATION Ea, ULONG EaLength) { - PFILE_FULL_EA_INFORMATION EaEnd = (PVOID)((PUINT8)Ea + EaLength); - NTSTATUS Result; - - Result = STATUS_SUCCESS; - for (; - EaEnd > Ea && 0 != Ea->NextEntryOffset; - Ea = (PVOID)((PUINT8)Ea + Ea->NextEntryOffset)) + NTSTATUS Result = STATUS_SUCCESS; + for (PFILE_FULL_EA_INFORMATION EaEnd = (PVOID)((PUINT8)Ea + EaLength); + EaEnd > Ea; FSP_NEXT_EA(Ea, EaEnd)) { Result = EnumerateEa(FileSystem, Context, Ea); if (!NT_SUCCESS(Result)) break; } - return Result; } diff --git a/src/dll/library.h b/src/dll/library.h index 17a67f7c..9970d31d 100644 --- a/src/dll/library.h +++ b/src/dll/library.h @@ -92,4 +92,7 @@ static inline BOOLEAN FspPathIsDrive(PWSTR FileName) L':' == FileName[1] && L'\0' == FileName[2]; } +#define FSP_NEXT_EA(Ea, EaEnd) \ + (0 != (Ea)->NextEntryOffset ? (PVOID)((PUINT8)(Ea) + (Ea)->NextEntryOffset) : (EaEnd)) + #endif diff --git a/src/dotnet/Interop.cs b/src/dotnet/Interop.cs index f69e991f..01e1a6af 100644 --- a/src/dotnet/Interop.cs +++ b/src/dotnet/Interop.cs @@ -908,9 +908,10 @@ namespace Fsp.Interop FullEaInformation *EndP = (FullEaInformation *)(Ea.ToInt64() + EaLength); Int32 Result; Result = 0/*STATUS_SUCCESS*/; - for (; - EndP > P && 0 != P->NextEntryOffset; - P = (FullEaInformation *)(((IntPtr)P).ToInt64() + P->NextEntryOffset)) + for (; EndP > P; + P = 0 != P->NextEntryOffset ? + (FullEaInformation *)(((IntPtr)P).ToInt64() + P->NextEntryOffset) : + EndP) { String EaName = Marshal.PtrToStringAnsi((IntPtr)P->EaName, P->EaNameLength); Byte[] EaValue = new Byte[P->EaValueLength]; diff --git a/src/sys/driver.h b/src/sys/driver.h index 02678013..03aa976f 100644 --- a/src/sys/driver.h +++ b/src/sys/driver.h @@ -573,6 +573,8 @@ NTSTATUS FspOplockFsctrl( FspNotifyFullChangeDirectory(NS, NL, FC, 0, 0, FALSE, 0, 0, 0, 0) #define FspNotifyReportChange(NS, NL, FN, FO, NP, F, A)\ FspNotifyFullReportChange(NS, NL, (PSTRING)(FN), FO, 0, (PSTRING)(NP), F, A, 0) +#define FSP_NEXT_EA(Ea, EaEnd) \ + (0 != (Ea)->NextEntryOffset ? (PVOID)((PUINT8)(Ea) + (Ea)->NextEntryOffset) : (EaEnd)) /* utility: synchronous work queue */ typedef struct diff --git a/src/sys/ea.c b/src/sys/ea.c index 4b0f0224..0edfcee5 100644 --- a/src/sys/ea.c +++ b/src/sys/ea.c @@ -97,17 +97,13 @@ static VOID FspFsvolQueryEaGetCopy( IoStatus->Status = STATUS_SUCCESS; IoStatus->Information = 0; DstBuf = DstBufBgn, PrevDstBuf = 0; - for (GetBuf = GetBufBgn; - GetBufEnd > GetBuf && 0 != GetBuf->NextEntryOffset; - GetBuf = (PVOID)((PUINT8)GetBuf + GetBuf->NextEntryOffset)) + for (GetBuf = GetBufBgn; GetBufEnd > GetBuf; GetBuf = FSP_NEXT_EA(GetBuf, GetBufEnd)) { GetName.Length = GetName.MaximumLength = GetBuf->EaNameLength; GetName.Buffer = GetBuf->EaName; /* ignore duplicate names */ - for (Get = GetBufBgn; - GetBuf > Get; - Get = (PVOID)((PUINT8)Get + Get->NextEntryOffset)) + for (Get = GetBufBgn; GetBuf > Get; Get = (PVOID)((PUINT8)Get + Get->NextEntryOffset)) { Name.Length = Name.MaximumLength = Get->EaNameLength; Name.Buffer = Get->EaName; @@ -126,9 +122,7 @@ static VOID FspFsvolQueryEaGetCopy( } Src = GetBuf; - for (SrcBuf = SrcBufBgn; - SrcBufEnd > SrcBuf && 0 != SrcBuf->NextEntryOffset; - SrcBuf = (PVOID)((PUINT8)SrcBuf + SrcBuf->NextEntryOffset)) + for (SrcBuf = SrcBufBgn; SrcBufEnd > SrcBuf; SrcBuf = FSP_NEXT_EA(SrcBuf, SrcBufEnd)) { Name.Length = Name.MaximumLength = SrcBuf->EaNameLength; Name.Buffer = SrcBuf->EaName; @@ -201,18 +195,14 @@ static VOID FspFsvolQueryEaIndexCopy( return; } - for (SrcBuf = SrcBufBgn; - EaIndex < *PEaIndex && - SrcBufEnd > SrcBuf && 0 != SrcBuf->NextEntryOffset; - SrcBuf = (PVOID)((PUINT8)SrcBuf + SrcBuf->NextEntryOffset), EaIndex++) + for (SrcBuf = SrcBufBgn; EaIndex < *PEaIndex && SrcBufEnd > SrcBuf; + SrcBuf = FSP_NEXT_EA(SrcBuf, SrcBufEnd), EaIndex++) ; IoStatus->Status = STATUS_SUCCESS; IoStatus->Information = 0; DstBuf = DstBufBgn, PrevDstBuf = 0; - for (; - SrcBufEnd > SrcBuf && 0 != SrcBuf->NextEntryOffset; - SrcBuf = (PVOID)((PUINT8)SrcBuf + SrcBuf->NextEntryOffset), EaIndex++) + for (; SrcBufEnd > SrcBuf; SrcBuf = FSP_NEXT_EA(SrcBuf, SrcBufEnd), EaIndex++) { if ((PUINT8)DstBuf + FIELD_OFFSET(FILE_FULL_EA_INFORMATION, EaName) > (PUINT8)DstBufEnd) break; @@ -256,7 +246,7 @@ static VOID FspFsvolQueryEaIndexCopy( if (SrcBufBgn == SrcBuf) IoStatus->Status = IndexSpecified ? STATUS_NONEXISTENT_EA_ENTRY : STATUS_NO_EAS_ON_FILE; - else if (SrcBufEnd > SrcBuf && 0 != SrcBuf->NextEntryOffset) + else if (SrcBufEnd > SrcBuf) IoStatus->Status = STATUS_BUFFER_TOO_SMALL; else IoStatus->Status = IndexSpecified && *PEaIndex != EaIndex ? @@ -503,8 +493,7 @@ static NTSTATUS FspFsvolSetEa( return Result; for (PFILE_FULL_EA_INFORMATION Ea = Buffer, EaEnd = (PVOID)((PUINT8)Ea + Length); - EaEnd > Ea && 0 != Ea->NextEntryOffset; - Ea = (PVOID)((PUINT8)Ea + Ea->NextEntryOffset)) + EaEnd > Ea; Ea = FSP_NEXT_EA(Ea, EaEnd)) { STRING Name;