fixed NtQueryDirectoryObject() to properly handle buffers that are not
large enough
Modified: trunk/reactos/ntoskrnl/ob/dirobj.c
_____
Modified: trunk/reactos/ntoskrnl/ob/dirobj.c
--- trunk/reactos/ntoskrnl/ob/dirobj.c 2005-01-26 13:52:53 UTC (rev
13308)
+++ trunk/reactos/ntoskrnl/ob/dirobj.c 2005-01-26 13:54:07 UTC (rev
13309)
@@ -231,6 +231,8 @@
ULONG RequiredSize = 0;
ULONG nDirectories = 0;
POBJECT_DIRECTORY_INFORMATION DirInfo =
(POBJECT_DIRECTORY_INFORMATION)TemporaryBuffer;
+
+ Status = STATUS_NO_MORE_ENTRIES;
KeAcquireSpinLock(&Directory->Lock, &OldLevel);
@@ -269,6 +271,8 @@
nDirectories++;
RequiredSize += EntrySize;
+
+ Status = STATUS_SUCCESS;
if(ReturnSingleEntry)
{
@@ -287,11 +291,13 @@
RequiredSize += EntrySize;
Status = STATUS_BUFFER_TOO_SMALL;
}
- else
- {
- /* just copy the entries that fit into the buffer */
- Status = STATUS_NO_MORE_ENTRIES;
- }
+
+ /* we couldn't query this entry, so leave the index that
will be stored
+ in Context to this entry so the caller can query it the
next time
+ he queries (hopefully with a buffer that is large enough
then...) */
+ NextEntry--;
+
+ /* just copy the entries that fit into the buffer */
break;
}
}
@@ -301,16 +307,18 @@
SkipEntries--;
}
}
+
+ if(!ReturnSingleEntry && ListEntry != &Directory->head)
+ {
+ /* there are more entries to enumerate but the buffer is
already full.
+ only tell this to the user if he queries multiple entries */
+ Status = STATUS_MORE_ENTRIES;
+ }
if(NT_SUCCESS(Status))
{
- if(SkipEntries > 0 || nDirectories == 0)
+ if(nDirectories > 0)
{
- /* we skipped more entries than the directory contains,
nothing more to do */
- Status = STATUS_NO_MORE_ENTRIES;
- }
- else
- {
_SEH_TRY
{
POBJECT_DIRECTORY_INFORMATION DestDirInfo =
(POBJECT_DIRECTORY_INFORMATION)Buffer;