VirtualBox

Ignore:
Timestamp:
Sep 16, 2009 12:59:18 PM (15 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/freebsd/VBoxNetAdp-freebsd.c

    r22875 r23068  
    121121                return RTErrConvertToErrno(rc);
    122122            }
    123             /* Create dev node */ 
     123            /* Create dev node */
    124124            VBoxNetAdpFreeBSDcdev = make_dev(&vboxnetadp_cdevsw, 0,
    125125                UID_ROOT, GID_WHEEL, 0600, VBOXNETADP_CTL_DEV_NAME);
     
    149149VBoxNetAdpFreeBSDCtrlioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, struct thread *td)
    150150{
    151     PVBOXNETADP pAdp = NULL;
     151    PVBOXNETADP pAdp;
    152152    PVBOXNETADPREQ pReq = (PVBOXNETADPREQ)data;
    153153    struct ifnet *ifp;
     
    157157    {
    158158        case VBOXNETADP_CTL_ADD:
    159             if (!(cmd & IOC_OUT))
    160                 return (EINVAL);
     159            if (   !(cmd & IOC_OUT)   /* paranoia*/
     160                || IOCPARM_LEN(iCmd) < sizeof(*pReq))
     161                return EINVAL;
    161162
    162163            rc = vboxNetAdpCreate(&pAdp);
    163164            if (RT_FAILURE(rc))
    164                 return (EINVAL);
    165 
    166             strncpy(pReq->szName, pAdp->szName, sizeof(pReq->szName));
    167             break;
     165                return EINVAL;
     166
     167            strncpy(pReq->szName, pAdp->szName, sizeof(pReq->szName) - 1);
     168            pReq->szName[sizeof(pReq->szName) - 1] = '\0';
     169            break;
     170
    168171        case VBOXNETADP_CTL_REMOVE:
     172            if (!memchr(pReq->szName, '\0', RT_MIN(sizeof(pReq->szName), IOCPARM_LEN(iCmd))))
     173                return EINVAL;
     174
    169175            pAdp = vboxNetAdpFindByName(pReq->szName);
    170             if (pAdp)
    171                 rc = vboxNetAdpDestroy(pAdp);
    172             else
    173                 return (EINVAL);
    174 
    175             if (RT_FAILURE(rc))
    176                 return (EINVAL);
    177 
    178             break;
     176            if (!pAdp)
     177                return EINVAL;
     178
     179            rc = vboxNetAdpDestroy(pAdp);
     180            if (RT_FAILURE(rc))
     181                return EINVAL;
     182
     183            break;
     184
    179185        default:
    180             return (EINVAL);
     186            return EINVAL;
    181187    }
    182188    return 0;
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