VirtualBox

Ignore:
Timestamp:
Aug 1, 2023 5:34:48 PM (22 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
158650
Message:

include/VBox/usbfilter.h,HostDrivers/VBoxUSB/USBFilter: IUSBDeviceFilter:
USB device interval filters don't work. bugref:10452

Main/Host,Main/USBDeviceFilter: Adding or removing global USB device
filters causes memory corruption wihch can lead to a deadlock or a SEGV
as the list of global USB device filters (llChildren) changes while
the list is being walked.

Frontends/VBoxManage: 'VBoxManage list usbfilters' doesn't display the
'Port' value of the device filter.

Frontends/VBoxManage: 'VBoxManage add usbfilter' and 'VBoxManage modify
usbfilter' both ignore the --product="Value" option.

Main/VirtualBox.xidl: Improve the IUSBDeviceFilter wording to make
things clearer in the 'VirtualBox Programming Guide and Reference Guide'
aka SDKRef.pdf.

HostDrivers/VBoxUSB/testcase/tstUSBFilter: Include a variety of USB
device filter entries which include the 'int:' prefix to fully exercise
the interval filter parsing code.

Location:
trunk/src/VBox/HostDrivers/VBoxUSB
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxUSB/USBFilter.cpp

    r98103 r100772  
    226226
    227227    /*
    228      * The string format is: "(<m>|([<m>]-[<n>]))|(<m>|([<m>]-[<n>]))+"
    229      * where <m> and <n> are numbers in the decimal, hex (0xNNN) or octal (0NNN)
    230      * form. Spaces are allowed around <m> and <n>.
     228     * The string format is: "int:((<m>)|([<m>]-[<n>]))(,(<m>)|([<m>]-[<n>]))*"
     229     * where <m> and <n> are numbers in decimal, hex (0xNNN) or octal (0NNN).
     230     * Spaces are allowed around <m> and <n>.
    231231     */
    232232    unsigned cSubExpressions = 0;
    233233    while (*pszExpr)
    234234    {
     235        if (!strncmp(pszExpr, RT_STR_TUPLE("int:")))
     236            pszExpr += strlen("int:");
     237
    235238        /*
    236239         * Skip remnants of the previous expression and any empty expressions.
    237240         * ('|' is the expression separator.)
    238241         */
    239         while (*pszExpr == '|' || RT_C_IS_BLANK(*pszExpr))
     242        while (*pszExpr == '|' || RT_C_IS_BLANK(*pszExpr) || *pszExpr == '(' || *pszExpr == ')')
    240243            pszExpr++;
    241244        if (!*pszExpr)
     
    256259        else
    257260        {
    258             /* M or M-N */
     261            /* M or M,N or M-N or M- */
    259262            rc = usbfilterReadNumber(&pszExpr, &u16First);
    260263            if (RT_SUCCESS(rc))
    261264            {
     265                pszExpr = usbfilterSkipBlanks(pszExpr);
    262266                if (*pszExpr == '-')
    263267                {
    264                     /* M-N */
     268                    pszExpr++;
     269                    if (*pszExpr) /* M-N */
     270                        rc = usbfilterReadNumber(&pszExpr, &u16Last);
     271                    else /* M- */
     272                        u16Last = UINT16_MAX;
     273                }
     274                else if (*pszExpr == ',')
     275                {
     276                    /* M,N */
    265277                    pszExpr++;
    266278                    rc = usbfilterReadNumber(&pszExpr, &u16Last);
     
    277289
    278290        /*
    279          * We should either be at the end of the string or at
    280          * an expression separator (|).
     291         * We should either be at the end of the string, at an expression separator (|),
     292         * or at the end of an interval filter (')').
    281293         */
    282         if (*pszExpr && *pszExpr != '|' )
     294        if (*pszExpr && *pszExpr != '|' && *pszExpr != ')')
    283295            return VERR_INVALID_PARAMETER;
    284296
     
    590602{
    591603    /*
    592      * The string format is: "(<m>|([<m>]-[<n>]))|(<m>|([<m>]-[<n>]))+"
    593      * where <m> and <n> are numbers in the decimal, hex (0xNNN) or octal (0NNN)
    594      * form. Spaces are allowed around <m> and <n>.
     604     * The string format is: "int:((<m>)|([<m>]-[<n>]))(,(<m>)|([<m>]-[<n>]))*"
     605     * where <m> and <n> are numbers in decimal, hex (0xNNN) or octal (0NNN).
     606     * Spaces are allowed around <m> and <n>.
    595607     */
    596608    while (*pszExpr)
    597609    {
     610        if (!strncmp(pszExpr, RT_STR_TUPLE("int:")))
     611            pszExpr += strlen("int:");
     612
    598613        /*
    599614         * Skip remnants of the previous expression and any empty expressions.
    600615         * ('|' is the expression separator.)
    601616         */
    602         while (*pszExpr == '|' || RT_C_IS_BLANK(*pszExpr))
     617        while (*pszExpr == '|' || RT_C_IS_BLANK(*pszExpr) || *pszExpr == '(' || *pszExpr == ')')
    603618            pszExpr++;
    604619        if (!*pszExpr)
     
    619634        else
    620635        {
    621             /* M or M-N */
     636            /* M or M,N or M-N or M- */
    622637            rc = usbfilterReadNumber(&pszExpr, &u16First);
    623638            if (RT_SUCCESS(rc))
     
    626641                if (*pszExpr == '-')
    627642                {
    628                     /* M-N */
     643                    pszExpr++;
     644                    if (*pszExpr) /* M-N */
     645                        rc = usbfilterReadNumber(&pszExpr, &u16Last);
     646                    else /* M- */
     647                        u16Last = UINT16_MAX;
     648                }
     649                else if (*pszExpr == ',')
     650                {
     651                    /* M,N */
    629652                    pszExpr++;
    630653                    rc = usbfilterReadNumber(&pszExpr, &u16Last);
     
    638661        }
    639662
    640         /* On success, we should either be at the end of the string or
    641            at an expression separator (|). */
    642         if (RT_SUCCESS(rc) && *pszExpr && *pszExpr != '|' )
     663        /* On success, we should either be at the end of the string, at an expression
     664         * separator (|), or at the end of an interval filter (')').
     665         */
     666        if (RT_SUCCESS(rc) && *pszExpr && *pszExpr != '|' && *pszExpr != ')')
    643667            rc = VERR_INVALID_PARAMETER;
    644668        if (RT_SUCCESS(rc))
  • trunk/src/VBox/HostDrivers/VBoxUSB/testcase/tstUSBFilter.cpp

    r98103 r100772  
    286286    TST_CHECK_EXPR(!USBFilterMatch(&Flt1, &Dev));
    287287
     288    /* numeric patterns - interval filters */
     289    TST_CHECK_RC(USBFilterSetNumExpression(&Flt1, USBFILTERIDX_VENDOR_ID, "int:0x0-0xffff", true));
     290    TST_CHECK_EXPR(USBFilterMatch(&Flt1, &Dev));
     291    TST_CHECK_RC(USBFilterSetNumExpression(&Flt1, USBFILTERIDX_VENDOR_ID, "int: 0x0 - 0xffff ", true));
     292    TST_CHECK_EXPR(USBFilterMatch(&Flt1, &Dev));
     293    TST_CHECK_RC(USBFilterSetNumExpression(&Flt1, USBFILTERIDX_PRODUCT_ID, "int:0x0028-", true));
     294    TST_CHECK_EXPR(USBFilterMatch(&Flt1, &Dev));
     295    TST_CHECK_RC(USBFilterSetNumExpression(&Flt1, USBFILTERIDX_DEVICE_REV, "int:-0x0045", true));
     296    TST_CHECK_EXPR(USBFilterMatch(&Flt1, &Dev));
     297    TST_CHECK_RC(USBFilterSetNumExpression(&Flt1, USBFILTERIDX_PORT, "int:1,4", true));
     298    TST_CHECK_EXPR(USBFilterMatch(&Flt1, &Dev));
     299    TST_CHECK_RC(USBFilterSetNumExpression(&Flt1, USBFILTERIDX_PORT, "int:( 1, 3 )", true));
     300    TST_CHECK_EXPR(USBFilterMatch(&Flt1, &Dev));
     301
    288302    TST_CHECK_RC(USBFilterSetNumExpression(&Flt1, USBFILTERIDX_VENDOR_ID, "39-59|0x256-0x101f|0xfffff-0xf000|0x1000-0x2000", true));
    289303    TST_CHECK_EXPR(USBFilterMatch(&Flt1, &Dev));
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette