Win10Pcap icon indicating copy to clipboard operation
Win10Pcap copied to clipboard

Order of operations error and missing exception handling

Open ChopperCharles opened this issue 5 years ago • 0 comments

In NDisDriver.c, line 1531 the following code will always evaluate to 0:

tag_us = (qinfo.TagHeader.UserPriority & 0x07 << 13) | (qinfo.TagHeader.CanonicalFormatId & 0x01 << 12) | (qinfo.TagHeader.VlanId & 0x0FFF);

This is because the shift operations take precedence over the and operations. To correct this, add parenthesis as such:

tag_us = ((qinfo.TagHeader.UserPriority & 0x07) << 13) | ((qinfo.TagHeader.CanonicalFormatId & 0x01) << 12) | (qinfo.TagHeader.VlanId & 0x0FFF);

In addition, anywhere there is a ProbeForRead or ProbeForWrite, these should be surrounded by a _try / _except block (and so should any additional access to the buffers). See https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/wdm/nf-wdm-probeforread for more information.

ChopperCharles avatar Jul 24 '19 18:07 ChopperCharles