VirtualBox

Changeset 40707 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 29, 2012 1:56:12 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
77166
Message:

Device\Parallel: Convert string functions to iprt ones. Introduced additional checks for detecting LPT port.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Parallel/DrvHostParallel.cpp

    r40666 r40707  
    349349    {
    350350        u32Size = 0;
    351         cmRet = CM_Get_Res_Des_Data_Size((PULONG)(&u32Size), nextLogConf, 0L); /** @todo r=bird: (PULONG)(&u32Size) - generally a bad idea, but not really a problem here though... Why don't you use ULONG for the size variable? Like 'ULONG cbBuf;'? */
     351        cmRet = CM_Get_Res_Des_Data_Size((PULONG)(&u32Size), nextLogConf, 0L);
    352352        if (cmRet != CR_SUCCESS)
    353353        {
     
    365365        {
    366366            CM_Free_Res_Des_Handle(nextLogConf);
    367             RTMemFree(pBuf);            /** @todo r=bird: LocalFree(pBuf) was the wrong free function! */
     367            RTMemFree(pBuf);
    368368            break;
    369369        }
     
    433433             char *pCh = NULL;
    434434             char* pTmpCh = NULL;
    435              if (strstr((char*)pBuf, "LPT"))        /** @todo Use IPRT equivalent? */
     435             if (RTStrStr((char*)pBuf, "LPT"))
    436436             {
    437437                 u32ParportAddr = drvHostWinFindIORangeResource(DeviceInfoData.DevInst);
     
    439439                 {
    440440                     /* Find parallel port name and update the shared data struncture */
    441                      pCh = strstr((char*)pBuf, "(");
    442                      pTmpCh = strstr((char *)pBuf, ")");
     441                     pCh = RTStrStr((char*)pBuf, "(");
     442                     pTmpCh = RTStrStr((char *)pBuf, ")");
    443443                     /* check for the confirmation for the availability of parallel port */
    444444                     if (!(pCh && pTmpCh))
    445445                     {
    446                          LogFlowFunc(("Parallel port Not Found \n"));
     446                         LogFlowFunc(("Parallel port Not Found. \n"));
    447447                         return VERR_NOT_FOUND;
    448448
     449                     }
     450                     if (((pTmpCh - (char *)pBuf) - (pCh - (char *)pBuf)) < 0) {
     451                         LogFlowFunc(("Parallel port string not properly formatted. \n"));
     452                         return VERR_NOT_FOUND;
    449453                     }
    450454                     /* check for the confirmation for the availability of parallel port */
    451                      if (!strncpy((char *)(pThis->u8ParportName), pCh+1, ((pTmpCh - (char *)pBuf) -
    452                                  (pCh - (char *)pBuf)) - 1))
     455                     if (RTStrCopyEx((char *)(pThis->u8ParportName), sizeof(pThis->u8ParportName),
     456                                      pCh+1, ((pTmpCh - (char *)pBuf) - (pCh - (char *)pBuf)) - 1))
    453457                     {
    454                          LogFlowFunc(("Parallel Port Not Found\n"));
     458                         LogFlowFunc(("Parallel Port Not Found. \n"));
    455459                         return VERR_NOT_FOUND;
    456460                     }
    457461                     *((char *)pThis->u8ParportName + (pTmpCh - (char *)pBuf) - (pCh - (char *)pBuf) + 1 ) = '\0';
     462
    458463                     /* checking again to make sure that we have got a valid name and in valid format too. */
    459                      if (!strstr((char *)pThis->u8ParportName, "LPT") ||
     464                     if (RTStrNCmp((char *)pThis->u8ParportName, "LPT", 3)) {
     465                         LogFlowFunc(("Parallel Port name \"LPT\" Not Found. \n"));
     466                         return VERR_NOT_FOUND;
     467                     }
     468
     469                     if (!RTStrStr((char *)pThis->u8ParportName, "LPT") ||
    460470                          !(pThis->u8ParportName[3] >= '0' && pThis->u8ParportName[3] <= '9')) {
    461                          pThis->u8ParportName[0] = '\0';
    462                          LogFlowFunc(("Printer Port Name Not Found\n"));
     471                         RT_BZERO(pThis->u8ParportName, sizeof(pThis->u8ParportName));
     472                         LogFlowFunc(("Printer Port Name Not Found. \n"));
    463473                         return VERR_NOT_FOUND;
    464474                     }
     
    980990
    981991    /* If we have the char port availabe use it , else I am not getting exclusive access to parallel port.
    982        Read and write will be done only if addresses are availabel
     992       Read and write will be done only if addresses are available
    983993    */
    984994    if (pThis->u8ParportName) {
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