From 05aaaf8a04cf5e245eb536c4e404129739059e47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Thu, 26 Mar 2015 14:52:16 +0000 Subject: [PATCH] [NTVDM] - Fix some english. - Validity checks for DosGetSftEntry returned pointer added. - Use unsigned indices for for-loops indices that are always positive. svn path=/trunk/; revision=66903 --- .../mvdm/ntvdm/dos/dos32krnl/bios.c | 7 ++++ .../mvdm/ntvdm/dos/dos32krnl/device.c | 2 +- .../subsystems/mvdm/ntvdm/dos/dos32krnl/dos.c | 21 +++++------ .../mvdm/ntvdm/dos/dos32krnl/dosfiles.c | 37 ++++++++++++++----- 4 files changed, 46 insertions(+), 21 deletions(-) diff --git a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/bios.c b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/bios.c index 67b5093997a..aa03db51588 100644 --- a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/bios.c +++ b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/bios.c @@ -57,6 +57,13 @@ BOOLEAN DosCheckInput(VOID) { PDOS_SFT_ENTRY SftEntry = DosGetSftEntry(DOS_INPUT_HANDLE); + if (SftEntry == NULL) + { + /* Invalid handle */ + DosLastError = ERROR_INVALID_HANDLE; // ERROR_FILE_NOT_FOUND + return FALSE; + } + switch (SftEntry->Type) { case DOS_SFT_ENTRY_WIN32: diff --git a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/device.c b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/device.c index a7a4c1f5513..5eb94155190 100644 --- a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/device.c +++ b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/device.c @@ -380,4 +380,4 @@ Cleanup: return Result; } - +/* EOF */ diff --git a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.c b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.c index a4a455debe0..683d7f2ed11 100644 --- a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.c +++ b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.c @@ -139,7 +139,7 @@ static BOOL IsConsoleHandle(HANDLE hHandle) static inline PDOS_SFT_ENTRY DosFindFreeSftEntry(VOID) { - INT i; + UINT i; for (i = 0; i < DOS_SFT_SIZE; i++) { @@ -154,7 +154,7 @@ static inline PDOS_SFT_ENTRY DosFindFreeSftEntry(VOID) static inline PDOS_SFT_ENTRY DosFindWin32SftEntry(HANDLE Handle) { - INT i; + UINT i; for (i = 0; i < DOS_SFT_SIZE; i++) { @@ -170,7 +170,7 @@ static inline PDOS_SFT_ENTRY DosFindWin32SftEntry(HANDLE Handle) static inline PDOS_SFT_ENTRY DosFindDeviceSftEntry(PDOS_DEVICE_NODE Device) { - INT i; + UINT i; for (i = 0; i < DOS_SFT_SIZE; i++) { @@ -209,7 +209,6 @@ WORD DosOpenHandle(HANDLE Handle) /* Check if the handle is already in the SFT */ SftEntry = DosFindWin32SftEntry(Handle); - if (SftEntry != NULL) { /* Already in the table, reference it */ @@ -266,7 +265,6 @@ WORD DosOpenDevice(PDOS_DEVICE_NODE Device) /* Check if the device is already in the SFT */ SftEntry = DosFindDeviceSftEntry(Device); - if (SftEntry != NULL) { /* Already in the table, reference it */ @@ -301,7 +299,7 @@ Finish: static VOID DosCopyHandleTable(LPBYTE DestinationTable) { - INT i; + UINT i; PDOS_PSP PspBlock; LPBYTE SourceTable; @@ -340,7 +338,6 @@ static VOID DosCopyHandleTable(LPBYTE DestinationTable) { /* Create a new SFT entry for it */ SftEntry = DosFindFreeSftEntry(); - if (SftEntry == NULL) { DPRINT1("Cannot create standard handle %d, the SFT is full!\n", i); @@ -1212,16 +1209,18 @@ Done: BOOLEAN DosHandleIoctl(BYTE ControlCode, WORD FileHandle) { - PDOS_SFT_ENTRY Entry = DosGetSftEntry(FileHandle); - PDOS_DEVICE_NODE Node = Entry->DeviceNode; + PDOS_SFT_ENTRY SftEntry = DosGetSftEntry(FileHandle); + PDOS_DEVICE_NODE Node; /* Make sure it exists and is a device */ - if (!Entry || Entry->Type != DOS_SFT_ENTRY_DEVICE) + if (!SftEntry || SftEntry->Type != DOS_SFT_ENTRY_DEVICE) { DosLastError = ERROR_FILE_NOT_FOUND; return FALSE; } + Node = SftEntry->DeviceNode; + switch (ControlCode) { /* Get Device Information */ @@ -2620,7 +2619,7 @@ VOID WINAPI DosInt21h(LPWORD Stack) { PDOS_SFT_ENTRY SftEntry = DosGetSftEntry(getBX()); - if (SftEntry->Type != DOS_SFT_ENTRY_WIN32) + if (SftEntry == NULL || SftEntry->Type != DOS_SFT_ENTRY_WIN32) { /* The handle is invalid */ Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF; diff --git a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dosfiles.c b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dosfiles.c index 5750a925577..65fd5fa0464 100644 --- a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dosfiles.c +++ b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dosfiles.c @@ -41,7 +41,7 @@ WORD DosCreateFileEx(LPWORD Handle, // // The article about OpenFile API: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365430(v=vs.85).aspx - // explains what are those AccessShareModes (see the uStyle flag). + // explains what those AccessShareModes are (see the uStyle flag). // /* Parse the access mode */ @@ -228,7 +228,6 @@ WORD DosCreateFileEx(LPWORD Handle, /* Open the DOS handle */ DosHandle = DosOpenHandle(FileHandle); - if (DosHandle == INVALID_DOS_HANDLE) { /* Close the file and return the error code */ @@ -268,7 +267,6 @@ WORD DosCreateFile(LPWORD Handle, /* Open the DOS handle */ DosHandle = DosOpenHandle(FileHandle); - if (DosHandle == INVALID_DOS_HANDLE) { /* Close the file and return the error code */ @@ -297,7 +295,7 @@ WORD DosOpenFile(LPWORD Handle, // // The article about OpenFile API: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365430(v=vs.85).aspx - // explains what are those AccessShareModes (see the uStyle flag). + // explains what those AccessShareModes are (see the uStyle flag). // /* Parse the access mode */ @@ -380,7 +378,6 @@ WORD DosOpenFile(LPWORD Handle, /* Open the DOS handle */ DosHandle = DosOpenHandle(FileHandle); - if (DosHandle == INVALID_DOS_HANDLE) { /* Close the file and return the error code */ @@ -403,6 +400,12 @@ WORD DosReadFile(WORD FileHandle, DPRINT("DosReadFile: FileHandle 0x%04X, Count 0x%04X\n", FileHandle, Count); + if (SftEntry == NULL) + { + /* Invalid handle */ + return ERROR_INVALID_HANDLE; + } + if (SftEntry->Type == DOS_SFT_ENTRY_WIN32) { DWORD BytesRead32 = 0; @@ -445,6 +448,12 @@ WORD DosWriteFile(WORD FileHandle, DPRINT("DosWriteFile: FileHandle 0x%04X, Count 0x%04X\n", FileHandle, Count); + if (SftEntry == NULL) + { + /* Invalid handle */ + return ERROR_INVALID_HANDLE; + } + if (SftEntry->Type == DOS_SFT_ENTRY_WIN32) { DWORD BytesWritten32 = 0; @@ -491,6 +500,12 @@ WORD DosSeekFile(WORD FileHandle, Offset, Origin); + if (SftEntry == NULL) + { + /* Invalid handle */ + return ERROR_INVALID_HANDLE; + } + if (SftEntry->Type == DOS_SFT_ENTRY_NONE) { /* Invalid handle */ @@ -534,6 +549,12 @@ BOOL DosFlushFileBuffers(WORD FileHandle) { PDOS_SFT_ENTRY SftEntry = DosGetSftEntry(FileHandle); + if (SftEntry == NULL) + { + /* Invalid handle */ + return ERROR_INVALID_HANDLE; + } + switch (SftEntry->Type) { case DOS_SFT_ENTRY_WIN32: @@ -544,14 +565,10 @@ BOOL DosFlushFileBuffers(WORD FileHandle) case DOS_SFT_ENTRY_DEVICE: { if (SftEntry->DeviceNode->FlushInputRoutine) - { SftEntry->DeviceNode->FlushInputRoutine(SftEntry->DeviceNode); - } if (SftEntry->DeviceNode->FlushOutputRoutine) - { SftEntry->DeviceNode->FlushOutputRoutine(SftEntry->DeviceNode); - } return TRUE; } @@ -563,3 +580,5 @@ BOOL DosFlushFileBuffers(WORD FileHandle) } } } + +/* EOF */