Build & bug fixes.

- Make WinDivert compile again under WDK/MSVC.
- Fix undiscovered bug where ip.TOS (8-bit field) was passed to ntohs.
This commit is contained in:
basil00
2015-07-18 16:46:21 +08:00
parent a15df9b886
commit 54f8640b89
3 changed files with 15 additions and 10 deletions
+3 -1
View File
@@ -383,6 +383,7 @@ extern HANDLE WinDivertOpen(const char *filter, WINDIVERT_LAYER layer,
{
struct windivert_ioctl_filter_s object[WINDIVERT_FILTER_MAXLEN];
UINT obj_len;
ERROR comp_err;
DWORD err;
HANDLE handle;
SC_HANDLE service;
@@ -403,7 +404,8 @@ extern HANDLE WinDivertOpen(const char *filter, WINDIVERT_LAYER layer,
}
// Compile the filter:
if (!WinDivertCompileFilter(filter, layer, object, &obj_len))
comp_err = WinDivertCompileFilter(filter, layer, object, &obj_len);
if (IS_ERROR(comp_err))
{
SetLastError(ERROR_INVALID_PARAMETER);
return INVALID_HANDLE_VALUE;
+10 -7
View File
@@ -1150,12 +1150,13 @@ static PEXPR WinDivertMakeZero(PPOOL pool)
*/
static PEXPR WinDivertMakeNumber(PPOOL pool, TOKEN *tok)
{
PEXPR expr;
if (tok->kind != TOKEN_NUMBER)
{
pool->error = MAKE_ERROR(WINDIVERT_ERROR_ASSERTION_FAILED, 0);
return NULL;
}
PEXPR expr = (PEXPR)WinDivertAlloc(pool, sizeof(EXPR));
expr = (PEXPR)WinDivertAlloc(pool, sizeof(EXPR));
if (expr == NULL)
{
return NULL;
@@ -1174,11 +1175,12 @@ static PEXPR WinDivertMakeNumber(PPOOL pool, TOKEN *tok)
*/
static PEXPR WinDivertMakeBinOp(PPOOL pool, KIND kind, PEXPR arg0, PEXPR arg1)
{
PEXPR expr;
if (arg0 == NULL || arg1 == NULL)
{
return NULL;
}
PEXPR expr = (PEXPR)WinDivertAlloc(pool, sizeof(EXPR));
expr = (PEXPR)WinDivertAlloc(pool, sizeof(EXPR));
if (expr == NULL)
{
return NULL;
@@ -1214,6 +1216,8 @@ static PEXPR WinDivertMakeIfThenElse(PPOOL pool, PEXPR cond, PEXPR th,
*/
static PEXPR WinDivertParseTest(PPOOL pool, TOKEN *toks, UINT *i)
{
PEXPR var, val;
KIND kind;
BOOL not = FALSE;
while (toks[*i].kind == TOKEN_NOT)
{
@@ -1287,9 +1291,8 @@ static PEXPR WinDivertParseTest(PPOOL pool, TOKEN *toks, UINT *i)
toks[*i].pos);
return NULL;
}
PEXPR var = WinDivertMakeVar(pool, toks[*i].kind);
var = WinDivertMakeVar(pool, toks[*i].kind);
*i = *i + 1;
KIND kind;
switch (toks[*i].kind)
{
case TOKEN_EQ:
@@ -1337,7 +1340,7 @@ static PEXPR WinDivertParseTest(PPOOL pool, TOKEN *toks, UINT *i)
toks[*i].pos);
return NULL;
}
PEXPR val = WinDivertMakeNumber(pool, toks + *i);
val = WinDivertMakeNumber(pool, toks + *i);
*i = *i + 1;
return WinDivertMakeBinOp(pool, kind, var, val);
}
@@ -1347,12 +1350,12 @@ static PEXPR WinDivertParseTest(PPOOL pool, TOKEN *toks, UINT *i)
*/
static PEXPR WinDivertParseArg(PPOOL pool, TOKEN *toks, UINT *i, INT depth)
{
PEXPR arg, th, el;
if (depth-- < 0)
{
pool->error = MAKE_ERROR(WINDIVERT_ERROR_TOO_DEEP, toks[*i].pos);
return NULL;
}
PEXPR arg, th, el;
switch (toks[*i].kind)
{
case TOKEN_OPEN:
@@ -2201,7 +2204,7 @@ extern BOOL WinDivertHelperEvalFilter(const char *filter,
val[0] = iphdr->HdrLength;
break;
case WINDIVERT_FILTER_FIELD_IP_TOS:
val[0] = ntohs(iphdr->TOS);
val[0] = iphdr->TOS;
break;
case WINDIVERT_FILTER_FIELD_IP_LENGTH:
val[0] = ntohs(iphdr->Length);
+2 -2
View File
@@ -2767,7 +2767,7 @@ static BOOL windivert_filter(PNET_BUFFER buffer, UINT32 if_idx,
field[0] = (UINT32)ip_header->HdrLength;
break;
case WINDIVERT_FILTER_FIELD_IP_TOS:
field[0] = (UINT32)RtlUshortByteSwap(ip_header->TOS);
field[0] = (UINT32)ip_header->TOS;
break;
case WINDIVERT_FILTER_FIELD_IP_LENGTH:
field[0] = (UINT32)RtlUshortByteSwap(ip_header->Length);
@@ -3234,6 +3234,7 @@ static filter_t windivert_filter_compile(windivert_ioctl_filter_t ioctl_filter,
goto windivert_filter_compile_exit;
}
break;
case WINDIVERT_FILTER_FIELD_IP_TOS:
case WINDIVERT_FILTER_FIELD_IP_TTL:
case WINDIVERT_FILTER_FIELD_IP_PROTOCOL:
case WINDIVERT_FILTER_FIELD_IPV6_TRAFFICCLASS:
@@ -3254,7 +3255,6 @@ static filter_t windivert_filter_compile(windivert_ioctl_filter_t ioctl_filter,
goto windivert_filter_compile_exit;
}
break;
case WINDIVERT_FILTER_FIELD_IP_TOS:
case WINDIVERT_FILTER_FIELD_IP_LENGTH:
case WINDIVERT_FILTER_FIELD_IP_ID:
case WINDIVERT_FILTER_FIELD_IP_CHECKSUM: