From 3360f1a1aec4e81cc21cdc79d19fa481a57dd93a Mon Sep 17 00:00:00 2001 From: Hartmut Birr Date: Thu, 13 Jan 2005 20:54:13 +0000 Subject: [PATCH] Fixed some length problems. svn path=/trunk/; revision=13031 --- reactos/drivers/fs/vfat/create.c | 11 ++--------- reactos/drivers/fs/vfat/dir.c | 2 +- reactos/drivers/fs/vfat/dirwr.c | 12 +++++++++++- reactos/drivers/fs/vfat/fcb.c | 15 ++++++++++----- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/reactos/drivers/fs/vfat/create.c b/reactos/drivers/fs/vfat/create.c index 4d07cbe9f26..f8fbcf4e598 100644 --- a/reactos/drivers/fs/vfat/create.c +++ b/reactos/drivers/fs/vfat/create.c @@ -200,15 +200,8 @@ FindFile (PDEVICE_EXTENSION DeviceExt, Parent, FileToFindU, DirContext->DirIndex); DPRINT ("FindFile: Path %wZ)\n",&Parent->PathNameU); - PathNameBufferLength = Parent->PathNameU.Length + LONGNAME_MAX_LENGTH + 2 * sizeof(WCHAR); - if (PathNameBufferLength > (USHRT_MAX - 2) * sizeof(WCHAR)) - { - /* A valid filename can't be so long. Do as if the file doesn't exist. */ - CHECKPOINT; - return STATUS_NO_SUCH_FILE; - } - - PathNameBuffer = ExAllocatePool(NonPagedPool, PathNameBufferLength); + PathNameBufferLength = LONGNAME_MAX_LENGTH * sizeof(WCHAR); + PathNameBuffer = ExAllocatePool(NonPagedPool, PathNameBufferLength + sizeof(WCHAR)); if (!PathNameBuffer) { CHECKPOINT1; diff --git a/reactos/drivers/fs/vfat/dir.c b/reactos/drivers/fs/vfat/dir.c index 12a2dbd4ad0..064ff79e373 100644 --- a/reactos/drivers/fs/vfat/dir.c +++ b/reactos/drivers/fs/vfat/dir.c @@ -306,7 +306,7 @@ NTSTATUS DoQuery (PVFAT_IRP_CONTEXT IrpContext) BOOLEAN First = FALSE; BOOLEAN FirstCall; VFAT_DIRENTRY_CONTEXT DirContext; - WCHAR LongNameBuffer[LONGNAME_MAX_LENGTH]; + WCHAR LongNameBuffer[LONGNAME_MAX_LENGTH + 1]; WCHAR ShortNameBuffer[13]; PIO_STACK_LOCATION Stack = IrpContext->Stack; diff --git a/reactos/drivers/fs/vfat/dirwr.c b/reactos/drivers/fs/vfat/dirwr.c index d5e9855fe7e..fa8923298dc 100644 --- a/reactos/drivers/fs/vfat/dirwr.c +++ b/reactos/drivers/fs/vfat/dirwr.c @@ -204,7 +204,7 @@ FATAddEntry (PDEVICE_EXTENSION DeviceExt, BOOLEAN SpacesFound; VFAT_DIRENTRY_CONTEXT DirContext; - WCHAR LongNameBuffer[LONGNAME_MAX_LENGTH]; + WCHAR LongNameBuffer[LONGNAME_MAX_LENGTH + 1]; WCHAR ShortNameBuffer[13]; DPRINT ("addEntry: Name='%wZ', Dir='%wZ'\n", NameU, &ParentFcb->PathNameU); @@ -363,6 +363,16 @@ FATAddEntry (PDEVICE_EXTENSION DeviceExt, } /* set dates and times */ KeQuerySystemTime (&SystemTime); +#if 0 + { + TIME_FIELDS tf; + RtlTimeToTimeFields (&SystemTime, &tf); + DPRINT1("%d.%d.%d %02d:%02d:%02d.%03d '%wZ'\n", + tf.Day, tf.Month, tf.Year, tf.Hour, + tf.Minute, tf.Second, tf.Milliseconds, + NameU); + } +#endif FsdSystemTimeToDosDateTime (DeviceExt, &SystemTime, &DirContext.DirEntry.Fat.CreationDate, &DirContext.DirEntry.Fat.CreationTime); DirContext.DirEntry.Fat.UpdateDate = DirContext.DirEntry.Fat.CreationDate; diff --git a/reactos/drivers/fs/vfat/fcb.c b/reactos/drivers/fs/vfat/fcb.c index 8b2b45fff19..64651156ab9 100644 --- a/reactos/drivers/fs/vfat/fcb.c +++ b/reactos/drivers/fs/vfat/fcb.c @@ -461,14 +461,17 @@ vfatMakeFCBFromDirEntry(PVCB vcb, UNICODE_STRING NameU; - PathNameLength = (directoryFCB->PathNameU.Length + 2 * sizeof(WCHAR) - + DirContext->LongNameU.Length) * sizeof(WCHAR); + PathNameLength = directoryFCB->PathNameU.Length + max(DirContext->LongNameU.Length, DirContext->ShortNameU.Length); + if (!vfatFCBIsRoot (directoryFCB)) + { + PathNameLength += sizeof(WCHAR); + } - if (PathNameLength > (USHRT_MAX - 2) * sizeof(WCHAR)) + if (PathNameLength > LONGNAME_MAX_LENGTH * sizeof(WCHAR)) { return STATUS_OBJECT_NAME_INVALID; } - PathNameBuffer = ExAllocatePool(NonPagedPool, PathNameLength); + PathNameBuffer = ExAllocatePool(NonPagedPool, PathNameLength + sizeof(WCHAR)); if (!PathNameBuffer) { return STATUS_INSUFFICIENT_RESOURCES; @@ -585,7 +588,9 @@ vfatDirFindFile (PDEVICE_EXTENSION pDeviceExt, PVOID Page = NULL; BOOLEAN First = TRUE; VFAT_DIRENTRY_CONTEXT DirContext; - WCHAR LongNameBuffer[LONGNAME_MAX_LENGTH]; + /* This buffer must have a size of 260 characters, because + vfatMakeFCBFromDirEntry can copy 20 name entries with 13 characters. */ + WCHAR LongNameBuffer[260]; WCHAR ShortNameBuffer[13]; BOOLEAN FoundLong = FALSE; BOOLEAN FoundShort = FALSE;