VirtualBox

Changeset 23059 in vbox for trunk/src/apps/adpctl


Ignore:
Timestamp:
Sep 16, 2009 10:26:02 AM (15 years ago)
Author:
vboxsync
Message:

VBoxNetAdpCtl: added adapter name validation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/apps/adpctl/VBoxNetAdpCtl.cpp

    r23049 r23059  
    201201}
    202202
     203int checkAdapterName(const char *pcszNameIn, char *pszNameOut)
     204{
     205    int iAdapterIndex = -1;
     206
     207    if (sscanf(pcszNameIn, "vboxnet%d", &iAdapterIndex) != 1
     208        || iAdapterIndex < 0 || iAdapterIndex > 99 )
     209    {
     210        fprintf(stderr, "Setting configuration for %s is not supported.\n", pcszNameIn);
     211        return 2;
     212    }
     213    sprintf(pszNameOut, "vboxnet%d", iAdapterIndex);
     214    if (strcmp(pszNameOut, pcszNameIn))
     215    {
     216        fprintf(stderr, "Invalid adapter name %s.\n", pcszNameIn);
     217        return 2;
     218    }
     219
     220    return 0;
     221}
     222
    203223int main(int argc, char *argv[])
    204224
    205225{
     226    char szAdapterName[VBOXNETADP_MAX_NAME_LEN];
    206227    char *pszAdapterName;
    207228    const char *pszAddress;
     
    242263            if (strcmp("remove", pszAddress) == 0)
    243264            {
    244                 snprintf(Req.szName, sizeof(Req.szName), "%s", pszAdapterName);
     265                rc = checkAdapterName(pszAdapterName, szAdapterName);
     266                if (rc)
     267                    return rc;
     268                snprintf(Req.szName, sizeof(Req.szName), "%s", szAdapterName);
    245269                return doIOCtl(VBOXNETADP_CTL_REMOVE, &Req);
    246270            }
     
    263287    }
    264288
    265     if (strncmp("vboxnet", pszAdapterName, 7))
    266     {
    267         fprintf(stderr, "Setting configuration for %s is not supported.\n", pszAdapterName);
    268         return 2;
    269     }
     289    rc = checkAdapterName(pszAdapterName, szAdapterName);
     290    if (rc)
     291        return rc;
     292
     293    pszAdapterName = szAdapterName;
    270294
    271295    if (fRemove)
Note: See TracChangeset for help on using the changeset viewer.

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