Skip to content

Commit

Permalink
[WSHTCPIP] Remove unneeded headers + Fix bugs.
Browse files Browse the repository at this point in the history
- Mismatch NTSTATUS/DWORD for win32 errors;
- Close handle returned from openTcpFile() with closeTcpFile().
  • Loading branch information
HBelusca committed Oct 8, 2023
1 parent 9021a14 commit 11b7064
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
40 changes: 19 additions & 21 deletions dll/win32/wshtcpip/iflist.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

#include "wshtcpip.h"

#define WIN32_NO_STATUS /* Tell Windows headers you'll use ntstatus.s from NDK */
#include <windows.h> /* Declare Windows Headers like you normally would */
#include <ntndk.h> /* Declare the NDK Headers */
#include <iptypes.h>
#include <wine/list.h>

Expand All @@ -29,7 +26,7 @@ BOOL AllocAndGetEntityArray(
ULONG outBufLen, outBufLenNeeded;
void* outBuf = NULL;
TCP_REQUEST_QUERY_INFORMATION_EX inTcpReq;
NTSTATUS Status;
DWORD dwError;
TDIEntityID *pEntities;

/* Set up Request */
Expand Down Expand Up @@ -62,7 +59,7 @@ BOOL AllocAndGetEntityArray(
if (outBuf == NULL)
break;

Status = NO_ERROR;
dwError = NO_ERROR;
if (!DeviceIoControl(
TcpFile,
IOCTL_TCP_QUERY_INFORMATION_EX,
Expand All @@ -72,16 +69,18 @@ BOOL AllocAndGetEntityArray(
outBufLen,
&outBufLenNeeded,
NULL))
Status = GetLastError();
{
dwError = GetLastError();
}

/* We need TDI_SUCCESS and the outBufLenNeeded must be equal or smaller
than our buffer (outBufLen). */
if (Status != NO_ERROR)
if (dwError != NO_ERROR)
{
HeapFree(hHeap, 0, outBuf);
break;
}
/* status = Success; was the buffer large enough? */
/* dwError = Success; was the buffer large enough? */
if (outBufLenNeeded <= outBufLen)
{
result = TRUE;
Expand Down Expand Up @@ -134,7 +133,7 @@ INT GetIPSNMPInfo(
&BufLenNeeded,
NULL))
{
DPRINT("DeviceIoControl (IPSNMPInfo) failed, Status %li!\n", GetLastError());
DPRINT("DeviceIoControl (IPSNMPInfo) failed, Error %ld!\n", GetLastError());
return WSAEFAULT;
}

Expand Down Expand Up @@ -164,7 +163,7 @@ INT GetTdiEntityType(
&BufLenNeeded,
NULL))
{
DPRINT("DeviceIoControl (TdiEntityType) failed, Status %li!\n", GetLastError());
DPRINT("DeviceIoControl (TdiEntityType) failed, Error %ld!\n", GetLastError());
return WSAEFAULT;
}

Expand Down Expand Up @@ -195,7 +194,7 @@ INT GetIFEntry(
&BufLenNeeded,
NULL))
{
DPRINT("DeviceIoControl (IFEntry) failed, Status %li!\n", GetLastError());
DPRINT("DeviceIoControl (IFEntry) failed, Error %ld!\n", GetLastError());
return WSAEFAULT;
}

Expand Down Expand Up @@ -230,20 +229,20 @@ WSHIoctl_GetInterfaceList(
DWORD outIDCount, i1, iAddr;
DWORD bCastAddr, outNumberOfBytes;
ULONG BufLenNeeded, BufLen, IFEntryLen, TdiType;
HANDLE TcpFile = 0;
HANDLE TcpFile = NULL;
HANDLE hHeap = GetProcessHeap();
DWORD LastErr;
INT res = -1;
NTSTATUS Status;
INT res;

/* Init Interface-ID-List */
IntfIDList = HeapAlloc(hHeap, 0, sizeof(*IntfIDList));
list_init(&IntfIDList->entry);

/* open tcp-driver */
LastErr = openTcpFile(&TcpFile, FILE_READ_DATA | FILE_WRITE_DATA);
if (!NT_SUCCESS(LastErr))
Status = openTcpFile(&TcpFile, FILE_READ_DATA | FILE_WRITE_DATA);
if (!NT_SUCCESS(Status))
{
res = (INT)LastErr;
res = RtlNtStatusToDosError(Status);
goto cleanup;
}

Expand Down Expand Up @@ -330,8 +329,7 @@ WSHIoctl_GetInterfaceList(
&BufLenNeeded,
NULL))
{
LastErr = GetLastError();
DPRINT("DeviceIoControl failed, Status %li!\n", LastErr);
DPRINT("DeviceIoControl failed, Error %ld!\n", GetLastError());
res = WSAEFAULT;
goto cleanup;
}
Expand Down Expand Up @@ -426,8 +424,8 @@ WSHIoctl_GetInterfaceList(
res = NO_ERROR;
cleanup:
DPRINT("WSHIoctl_GetInterfaceList - CLEANUP\n");
if (TcpFile != 0)
NtClose(TcpFile);
if (TcpFile != NULL)
closeTcpFile(TcpFile);
if (pIFEntry != NULL)
HeapFree(hHeap, 0, pIFEntry);
LIST_FOR_EACH_ENTRY_SAFE_REV(pIntfIDItem, pIntfIDNext,
Expand Down
2 changes: 1 addition & 1 deletion dll/win32/wshtcpip/wshtcpip.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ SendRequest(

closeTcpFile(TcpCC);

DPRINT("DeviceIoControl: %ld\n", ((Success != FALSE) ? 0 : GetLastError()));
DPRINT("DeviceIoControl: %ld\n", (Success ? NO_ERROR : GetLastError()));

if (!Success)
return WSAEINVAL;
Expand Down

0 comments on commit 11b7064

Please sign in to comment.