VirtualBox

Ignore:
Timestamp:
Sep 16, 2009 12:59:18 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
52402
Message:

VBoxNetAdp: ioctl cleanup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxNetAdp/darwin/VBoxNetAdp-darwin.cpp

    r20374 r23068  
    867867static int VBoxNetAdpDarwinIOCtl(dev_t Dev, u_long iCmd, caddr_t pData, int fFlags, struct proc *pProcess)
    868868{
    869     int rc = VINF_SUCCESS;
    870869    uint32_t cbReq = IOCPARM_LEN(iCmd);
    871870    PVBOXNETADPREQ pReq = (PVBOXNETADPREQ)pData;
     871    int rc;
    872872
    873873    Log(("VBoxNetAdpDarwinIOCtl: param len %#x; iCmd=%#lx\n", cbReq, iCmd));
     
    875875    {
    876876        case IOCBASECMD(VBOXNETADP_CTL_ADD):
    877             if ((IOC_DIRMASK & iCmd) == IOC_OUT)
    878             {
    879                 PVBOXNETADP pNew;
    880                 rc = vboxNetAdpCreate(&pNew);
    881                 if (RT_SUCCESS(rc))
    882                 {
    883                     if (cbReq < sizeof(VBOXNETADPREQ))
    884                     {
    885                         OSDBGPRINT(("VBoxNetAdpDarwinIOCtl: param len %#x < req size %#x; iCmd=%#lx\n", cbReq, sizeof(VBOXNETADPREQ), iCmd));
    886                         return EINVAL;
    887                     }
    888                     strncpy(pReq->szName, pNew->szName, sizeof(pReq->szName));
    889                 }
    890             }
     877        {
     878            if (   (IOC_DIRMASK & iCmd) != IOC_OUT
     879                || cbReq < sizeof(VBOXNETADPREQ))
     880                return EINVAL;
     881
     882            PVBOXNETADP pNew;
     883            rc = vboxNetAdpCreate(&pNew);
     884            if (RT_FAILURE(rc))
     885                return EINVAL;
     886
     887            Assert(strlen(pReq->szName) < sizeof(pReq->szName));
     888            strncpy(pReq->szName, pNew->szName, sizeof(pReq->szName) - 1);
     889            pReq->szName[sizeof(pReq->szName) - 1] = '\0';
     890            Log(("VBoxNetAdpDarwinIOCtl: Added '%s'\n", pReq->szName));
    891891            break;
     892        }
    892893
    893894        case IOCBASECMD(VBOXNETADP_CTL_REMOVE):
    894             for (unsigned i = 0; i < RT_ELEMENTS(g_aAdapters); i++)
    895             {
    896                 PVBOXNETADP pThis = &g_aAdapters[i];
    897                 rc = VERR_NOT_FOUND;
    898                 if (strncmp(pThis->szName, pReq->szName, VBOXNETADP_MAX_NAME_LEN) == 0)
    899                     if (ASMAtomicReadU32((uint32_t volatile *)&pThis->enmState) == kVBoxNetAdpState_Active)
    900                     {
    901                         rc = vboxNetAdpDestroy(pThis);
    902                         break;
    903                     }
    904             }
     895        {
     896            if (!memchr(pReq->szName, '\0', RT_MIN(cbReq, sizeof(pReq->szName))))
     897                return EINVAL;
     898
     899            PVBOXNETADP pAdp = vboxNetAdpFindByName(pReq->szName);
     900            if (!pAdp)
     901                return EINVAL;
     902
     903            rc = vboxNetAdpDestroy(pAdp);
     904            if (RT_FAILURE(rc))
     905                return EINVAL;
     906            Log(("VBoxNetAdpDarwinIOCtl: Removed %s\n", pReq->szName));
    905907            break;
     908        }
     909
    906910        default:
    907911            OSDBGPRINT(("VBoxNetAdpDarwinIOCtl: unknown command %x.\n", IOCBASECMD(iCmd)));
    908             rc = VERR_INVALID_PARAMETER;
    909             break;
    910     }
    911 
    912     return RT_SUCCESS(rc) ? 0 : EINVAL;
     912            return EINVAL;
     913    }
     914
     915    return 0;
    913916}
    914917
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