- Fixed a bug, which prevents an opening of files, if the file name contains short path names.

svn path=/trunk/; revision=9982
This commit is contained in:
Hartmut Birr 2004-07-03 17:31:30 +00:00
parent ba93d9c7b0
commit e251c53983
2 changed files with 73 additions and 21 deletions

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: create.c,v 1.68 2004/06/23 20:23:59 hbirr Exp $
/* $Id: create.c,v 1.69 2004/07/03 17:31:30 hbirr Exp $
*
* PROJECT: ReactOS kernel
* FILE: drivers/fs/vfat/create.c
@ -339,34 +339,35 @@ VfatOpenFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
PVFATFCB ParentFcb;
PVFATFCB Fcb;
NTSTATUS Status;
UNICODE_STRING NameU;
WCHAR Name[MAX_PATH];
ULONG Size;
ULONG MediaChangeCount;
// PDEVICE_OBJECT DeviceObject = DeviceExt->StorageDevice->Vpb->DeviceObject;
DPRINT ("VfatOpenFile(%08lx, %08lx, '%wZ')\n", DeviceExt, FileObject, FileNameU);
DPRINT ("VfatOpenFile(%08lx, %08lx, '%wZ')\n", DeviceExt, FileObject, &FileObject->FileName);
if (FileObject->RelatedFileObject)
{
DPRINT ("Converting relative filename to absolute filename\n");
NameU.Buffer = Name;
NameU.Length = 0;
NameU.MaximumLength = sizeof(Name);
Fcb = FileObject->RelatedFileObject->FsContext;
RtlCopyUnicodeString(&NameU, &Fcb->PathNameU);
RtlCopyUnicodeString(FileNameU, &Fcb->PathNameU);
if (!vfatFCBIsRoot(Fcb))
{
NameU.Buffer[NameU.Length / sizeof(WCHAR)] = L'\\';
NameU.Length += sizeof(WCHAR);
RtlAppendUnicodeToString(FileNameU, L"\\");
}
RtlAppendUnicodeStringToString(&NameU, FileNameU);
NameU.Buffer[NameU.Length / sizeof(WCHAR)] = 0;
FileNameU = &NameU;
RtlAppendUnicodeStringToString(FileNameU, &FileObject->FileName);
}
else
{
RtlCopyUnicodeString(FileNameU, &FileObject->FileName);
}
if (FileNameU->Length > sizeof(WCHAR) &&
FileNameU->Buffer[FileNameU->Length / sizeof(WCHAR) - 1] == L'\\')
{
FileNameU->Length -= sizeof(WCHAR);
}
FileNameU->Buffer[FileNameU->Length / sizeof(WCHAR)] = 0;
DPRINT ("PathName to open: '%wZ'\n", FileNameU);
@ -425,6 +426,10 @@ VfatOpenFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
return Status;
}
}
else
{
RtlCopyUnicodeString(FileNameU, &Fcb->PathNameU);
}
if (Fcb->Flags & FCB_DELETE_PENDING)
{
vfatReleaseFCB (DeviceExt, Fcb);
@ -492,6 +497,8 @@ VfatCreateFile (PDEVICE_OBJECT DeviceObject, PIRP Irp)
BOOLEAN PagingFileCreate = FALSE;
LARGE_INTEGER AllocationSize;
BOOLEAN Dots;
UNICODE_STRING NameU;
WCHAR NameW[MAX_PATH];
/* Unpack the various parameters. */
Stack = IoGetCurrentIrpStackLocation (Irp);
@ -568,8 +575,12 @@ VfatCreateFile (PDEVICE_OBJECT DeviceObject, PIRP Irp)
}
}
NameU.Buffer = NameW;
NameU.Length = 0;
NameU.MaximumLength = sizeof(NameW);
/* Try opening the file. */
Status = VfatOpenFile (DeviceExt, FileObject, &FileObject->FileName);
Status = VfatOpenFile (DeviceExt, FileObject, &NameU);
/*
* If the directory containing the file to open doesn't exist then
@ -594,7 +605,7 @@ VfatCreateFile (PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
ULONG Attributes;
Attributes = Stack->Parameters.Create.FileAttributes;
Status = VfatAddEntry (DeviceExt, &FileObject->FileName, FileObject, RequestedOptions,
Status = VfatAddEntry (DeviceExt, &NameU, FileObject, RequestedOptions,
(UCHAR)(Attributes & FILE_ATTRIBUTE_VALID_FLAGS));
if (NT_SUCCESS (Status))
{

View file

@ -1,4 +1,4 @@
/* $Id: fcb.c,v 1.37 2004/01/28 20:53:46 ekohl Exp $
/* $Id: fcb.c,v 1.38 2004/07/03 17:31:30 hbirr Exp $
*
*
* FILE: drivers/fs/vfat/fcb.c
@ -594,6 +594,7 @@ vfatGetFCBForFile (PDEVICE_EXTENSION pVCB,
UNICODE_STRING NameU;
UNICODE_STRING RootNameU;
PWCHAR curr, prev, last;
ULONG Length;
DPRINT ("vfatGetFCBForFile (%x,%x,%x,%wZ)\n",
pVCB,
@ -626,6 +627,24 @@ vfatGetFCBForFile (PDEVICE_EXTENSION pVCB,
NameU.Buffer = pFileNameU->Buffer;
NameU.MaximumLength = NameU.Length = (curr - pFileNameU->Buffer) * sizeof(WCHAR);
FCB = vfatGrabFCBFromTable(pVCB, &NameU);
if (FCB)
{
Length = (curr - pFileNameU->Buffer) * sizeof(WCHAR);
if (Length != FCB->PathNameU.Length)
{
if (pFileNameU->Length + FCB->PathNameU.Length - Length > pFileNameU->MaximumLength)
{
vfatReleaseFCB (pVCB, FCB);
return STATUS_OBJECT_NAME_INVALID;
}
memmove(pFileNameU->Buffer + FCB->PathNameU.Length / sizeof(WCHAR),
curr, pFileNameU->Length - Length);
pFileNameU->Length += FCB->PathNameU.Length - Length;
curr = pFileNameU->Buffer + FCB->PathNameU.Length / sizeof(WCHAR);
last = pFileNameU->Buffer + pFileNameU->Length / sizeof(WCHAR) - 1;
}
memcpy(pFileNameU->Buffer, FCB->PathNameU.Buffer, FCB->PathNameU.Length);
}
}
else
{
@ -637,8 +656,10 @@ vfatGetFCBForFile (PDEVICE_EXTENSION pVCB,
FCB = vfatOpenRootFCB(pVCB);
curr = pFileNameU->Buffer;
}
curr++;
parentFCB = NULL;
prev = curr;
while (curr <= last)
{
if (parentFCB)
@ -659,13 +680,34 @@ vfatGetFCBForFile (PDEVICE_EXTENSION pVCB,
return STATUS_OBJECT_PATH_NOT_FOUND;
}
parentFCB = FCB;
NameU.Buffer = pFileNameU->Buffer;
if (prev < curr)
{
Length = (curr - prev) * sizeof(WCHAR);
if (Length != parentFCB->LongNameU.Length)
{
if (pFileNameU->Length + parentFCB->LongNameU.Length - Length > pFileNameU->MaximumLength)
{
vfatReleaseFCB (pVCB, parentFCB);
return STATUS_OBJECT_NAME_INVALID;
}
memmove(prev + parentFCB->LongNameU.Length / sizeof(WCHAR), curr,
pFileNameU->Length - (curr - pFileNameU->Buffer) * sizeof(WCHAR));
pFileNameU->Length += parentFCB->LongNameU.Length - Length;
curr = prev + parentFCB->LongNameU.Length / sizeof(WCHAR);
last = pFileNameU->Buffer + pFileNameU->Length / sizeof(WCHAR) - 1;
}
memcpy(prev, parentFCB->LongNameU.Buffer, parentFCB->LongNameU.Length);
}
curr++;
prev = curr;
while (*curr != L'\\' && curr <= last)
{
curr++;
}
NameU.MaximumLength = NameU.Length = (curr - NameU.Buffer) * sizeof(WCHAR);
NameU.Buffer = pFileNameU->Buffer;
NameU.Length = (curr - NameU.Buffer) * sizeof(WCHAR);
NameU.MaximumLength = pFileNameU->MaximumLength;
DPRINT("%wZ\n", &NameU);
FCB = vfatGrabFCBFromTable(pVCB, &NameU);
if (FCB == NULL)
{
@ -694,7 +736,6 @@ vfatGetFCBForFile (PDEVICE_EXTENSION pVCB,
return status;
}
}
curr++;
}
*pParentFCB = parentFCB;