mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 07:53:07 +00:00
- 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:
parent
ba93d9c7b0
commit
e251c53983
2 changed files with 73 additions and 21 deletions
|
@ -16,7 +16,7 @@
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* 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
|
* PROJECT: ReactOS kernel
|
||||||
* FILE: drivers/fs/vfat/create.c
|
* FILE: drivers/fs/vfat/create.c
|
||||||
|
@ -339,34 +339,35 @@ VfatOpenFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
|
||||||
PVFATFCB ParentFcb;
|
PVFATFCB ParentFcb;
|
||||||
PVFATFCB Fcb;
|
PVFATFCB Fcb;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
UNICODE_STRING NameU;
|
|
||||||
WCHAR Name[MAX_PATH];
|
|
||||||
ULONG Size;
|
ULONG Size;
|
||||||
ULONG MediaChangeCount;
|
ULONG MediaChangeCount;
|
||||||
|
|
||||||
// PDEVICE_OBJECT DeviceObject = DeviceExt->StorageDevice->Vpb->DeviceObject;
|
// 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)
|
if (FileObject->RelatedFileObject)
|
||||||
{
|
{
|
||||||
DPRINT ("Converting relative filename to absolute filename\n");
|
DPRINT ("Converting relative filename to absolute filename\n");
|
||||||
|
|
||||||
NameU.Buffer = Name;
|
|
||||||
NameU.Length = 0;
|
|
||||||
NameU.MaximumLength = sizeof(Name);
|
|
||||||
|
|
||||||
Fcb = FileObject->RelatedFileObject->FsContext;
|
Fcb = FileObject->RelatedFileObject->FsContext;
|
||||||
RtlCopyUnicodeString(&NameU, &Fcb->PathNameU);
|
RtlCopyUnicodeString(FileNameU, &Fcb->PathNameU);
|
||||||
if (!vfatFCBIsRoot(Fcb))
|
if (!vfatFCBIsRoot(Fcb))
|
||||||
{
|
{
|
||||||
NameU.Buffer[NameU.Length / sizeof(WCHAR)] = L'\\';
|
RtlAppendUnicodeToString(FileNameU, L"\\");
|
||||||
NameU.Length += sizeof(WCHAR);
|
|
||||||
}
|
}
|
||||||
RtlAppendUnicodeStringToString(&NameU, FileNameU);
|
RtlAppendUnicodeStringToString(FileNameU, &FileObject->FileName);
|
||||||
NameU.Buffer[NameU.Length / sizeof(WCHAR)] = 0;
|
|
||||||
FileNameU = &NameU;
|
|
||||||
}
|
}
|
||||||
|
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);
|
DPRINT ("PathName to open: '%wZ'\n", FileNameU);
|
||||||
|
|
||||||
|
@ -425,6 +426,10 @@ VfatOpenFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RtlCopyUnicodeString(FileNameU, &Fcb->PathNameU);
|
||||||
|
}
|
||||||
if (Fcb->Flags & FCB_DELETE_PENDING)
|
if (Fcb->Flags & FCB_DELETE_PENDING)
|
||||||
{
|
{
|
||||||
vfatReleaseFCB (DeviceExt, Fcb);
|
vfatReleaseFCB (DeviceExt, Fcb);
|
||||||
|
@ -492,6 +497,8 @@ VfatCreateFile (PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
||||||
BOOLEAN PagingFileCreate = FALSE;
|
BOOLEAN PagingFileCreate = FALSE;
|
||||||
LARGE_INTEGER AllocationSize;
|
LARGE_INTEGER AllocationSize;
|
||||||
BOOLEAN Dots;
|
BOOLEAN Dots;
|
||||||
|
UNICODE_STRING NameU;
|
||||||
|
WCHAR NameW[MAX_PATH];
|
||||||
|
|
||||||
/* Unpack the various parameters. */
|
/* Unpack the various parameters. */
|
||||||
Stack = IoGetCurrentIrpStackLocation (Irp);
|
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. */
|
/* 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
|
* If the directory containing the file to open doesn't exist then
|
||||||
|
@ -594,7 +605,7 @@ VfatCreateFile (PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
||||||
{
|
{
|
||||||
ULONG Attributes;
|
ULONG Attributes;
|
||||||
Attributes = Stack->Parameters.Create.FileAttributes;
|
Attributes = Stack->Parameters.Create.FileAttributes;
|
||||||
Status = VfatAddEntry (DeviceExt, &FileObject->FileName, FileObject, RequestedOptions,
|
Status = VfatAddEntry (DeviceExt, &NameU, FileObject, RequestedOptions,
|
||||||
(UCHAR)(Attributes & FILE_ATTRIBUTE_VALID_FLAGS));
|
(UCHAR)(Attributes & FILE_ATTRIBUTE_VALID_FLAGS));
|
||||||
if (NT_SUCCESS (Status))
|
if (NT_SUCCESS (Status))
|
||||||
{
|
{
|
||||||
|
|
|
@ -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
|
* FILE: drivers/fs/vfat/fcb.c
|
||||||
|
@ -594,6 +594,7 @@ vfatGetFCBForFile (PDEVICE_EXTENSION pVCB,
|
||||||
UNICODE_STRING NameU;
|
UNICODE_STRING NameU;
|
||||||
UNICODE_STRING RootNameU;
|
UNICODE_STRING RootNameU;
|
||||||
PWCHAR curr, prev, last;
|
PWCHAR curr, prev, last;
|
||||||
|
ULONG Length;
|
||||||
|
|
||||||
DPRINT ("vfatGetFCBForFile (%x,%x,%x,%wZ)\n",
|
DPRINT ("vfatGetFCBForFile (%x,%x,%x,%wZ)\n",
|
||||||
pVCB,
|
pVCB,
|
||||||
|
@ -626,6 +627,24 @@ vfatGetFCBForFile (PDEVICE_EXTENSION pVCB,
|
||||||
NameU.Buffer = pFileNameU->Buffer;
|
NameU.Buffer = pFileNameU->Buffer;
|
||||||
NameU.MaximumLength = NameU.Length = (curr - pFileNameU->Buffer) * sizeof(WCHAR);
|
NameU.MaximumLength = NameU.Length = (curr - pFileNameU->Buffer) * sizeof(WCHAR);
|
||||||
FCB = vfatGrabFCBFromTable(pVCB, &NameU);
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -637,8 +656,10 @@ vfatGetFCBForFile (PDEVICE_EXTENSION pVCB,
|
||||||
FCB = vfatOpenRootFCB(pVCB);
|
FCB = vfatOpenRootFCB(pVCB);
|
||||||
curr = pFileNameU->Buffer;
|
curr = pFileNameU->Buffer;
|
||||||
}
|
}
|
||||||
curr++;
|
|
||||||
parentFCB = NULL;
|
parentFCB = NULL;
|
||||||
|
prev = curr;
|
||||||
|
|
||||||
while (curr <= last)
|
while (curr <= last)
|
||||||
{
|
{
|
||||||
if (parentFCB)
|
if (parentFCB)
|
||||||
|
@ -659,13 +680,34 @@ vfatGetFCBForFile (PDEVICE_EXTENSION pVCB,
|
||||||
return STATUS_OBJECT_PATH_NOT_FOUND;
|
return STATUS_OBJECT_PATH_NOT_FOUND;
|
||||||
}
|
}
|
||||||
parentFCB = FCB;
|
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;
|
prev = curr;
|
||||||
while (*curr != L'\\' && curr <= last)
|
while (*curr != L'\\' && curr <= last)
|
||||||
{
|
{
|
||||||
curr++;
|
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);
|
FCB = vfatGrabFCBFromTable(pVCB, &NameU);
|
||||||
if (FCB == NULL)
|
if (FCB == NULL)
|
||||||
{
|
{
|
||||||
|
@ -694,7 +736,6 @@ vfatGetFCBForFile (PDEVICE_EXTENSION pVCB,
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
curr++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*pParentFCB = parentFCB;
|
*pParentFCB = parentFCB;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue