VirtualBox

Changeset 42180 in vbox for trunk/src


Ignore:
Timestamp:
Jul 17, 2012 12:51:06 PM (12 years ago)
Author:
vboxsync
Message:

NAT:TFTP: * according to rfc 2349, option value handler increased up to handle up to 64-bit values.

  • range check for blksize (it should be less UINT16_MAX)
  • OACK returns all requested supported options.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/slirp/tftp.c

    r42020 r42180  
    5858{
    5959    int fRequested;
    60     int u16Value;
     60    uint64_t u64Value;
    6161} TFPTPSESSIONOPTDESC, *PTFPTPSESSIONOPTDESC;
    6262
     
    7373    TFPTPSESSIONOPTDESC OptionBlkSize;
    7474    TFPTPSESSIONOPTDESC OptionTSize;
    75     TFPTPSESSIONOPTDESC OptionSize;
    7675    TFPTPSESSIONOPTDESC OptionTimeout;
    7776} TFTPSESSION, *PTFTPSESSION, **PPTFTPSESSION;
     
    244243{
    245244    int rc  = VINF_SUCCESS;
    246     rc = RTStrToInt16Full(pcszRawOption, 0, (int16_t *)&pTftpSessionOption->u16Value);
     245    rc = RTStrToInt64Full(pcszRawOption, 0, (int64_t *)&pTftpSessionOption->u64Value);
    247246    AssertRCReturn(rc, rc);
    248247    pTftpSessionOption->fRequested = 1;
     
    293292            if (!RTStrICmp("blksize", g_TftpDesc[idxOptionArg].pszName))
    294293                rc = tftpSessionParseAndMarkOption(pszTftpRRQRaw, &pTftpSession->OptionBlkSize);
    295             else if (!RTStrICmp("size", g_TftpDesc[idxOptionArg].pszName))
    296                 rc = tftpSessionParseAndMarkOption(pszTftpRRQRaw, &pTftpSession->OptionSize);
    297             else if (!RTStrICmp("tsize", g_TftpDesc[idxOptionArg].pszName))
     294            if (!RTStrICmp("tsize", g_TftpDesc[idxOptionArg].pszName))
    298295                rc = tftpSessionParseAndMarkOption(pszTftpRRQRaw, &pTftpSession->OptionTSize);
    299             else if (!RTStrICmp("timeoute", g_TftpDesc[idxOptionArg].pszName))
    300                 rc = tftpSessionParseAndMarkOption(pszTftpRRQRaw, &pTftpSession->OptionSize);
     296            if (!RTStrICmp("timeoute", g_TftpDesc[idxOptionArg].pszName))
     297                rc = tftpSessionParseAndMarkOption(pszTftpRRQRaw, &pTftpSession->OptionTimeout);
     298/*
     299            @todo: process unrecognized options ??
    301300            else
    302301                rc = VERR_INVALID_PARAMETER;
     302*/
    303303            if (RT_FAILURE(rc))
    304304            {
     
    397397    size_t cbSessionFileName;
    398398    int rc = VINF_SUCCESS;
     399    LogFlowFuncEnter();
    399400    cbSessionFileName = RTStrPrintf(aszSessionFileName, TFTP_FILENAME_MAX, "%s/%s",
    400401                    tftp_prefix, pTftpSession->pszFilename);
     
    404405        return VERR_INTERNAL_ERROR;
    405406    }
     407    LogFunc(("aszSessionFileName: %s\n", aszSessionFileName));
    406408
    407409    if (!RTFileExists(aszSessionFileName))
     
    439441
    440442    if (pTftpSession->OptionTSize.fRequested)
    441         pTftpSession->OptionTSize.u16Value = (uint16_t)cbSessionFile;
    442     if (   !pTftpSession->OptionBlkSize.u16Value
     443    {
     444       pTftpSession->OptionTSize.u64Value = cbSessionFile;
     445    }
     446    if (   !pTftpSession->OptionBlkSize.u64Value
    443447        && !pTftpSession->OptionBlkSize.fRequested)
    444448    {
    445         pTftpSession->OptionBlkSize.u16Value = 1428;
     449        pTftpSession->OptionBlkSize.u64Value = 1428;
    446450    }
    447451    LogFlowFuncLeaveRC(rc);
     
    484488    AssertPtrReturn(pu8Data, VERR_INVALID_PARAMETER);
    485489    AssertPtrReturn(pcbReadData, VERR_INVALID_PARAMETER);
     490    AssertReturn(pcTftpSession->OptionBlkSize.u64Value < UINT16_MAX, VERR_INVALID_PARAMETER);
    486491    LogFlowFunc(("pcTftpSession:%p, pu8Data:%p, pcbReadData:%p\n",
    487492                    pcTftpSession,
     
    489494                    pcbReadData));
    490495
    491     u16BlkSize = pcTftpSession->OptionBlkSize.u16Value;
     496    u16BlkSize = (uint16_t)pcTftpSession->OptionBlkSize.u64Value;
    492497    rc = pftpSessionOpenFile(pData, pcTftpSession, &hSessionFile);
    493498    if (RT_FAILURE(rc))
     
    524529}
    525530
    526 DECLINLINE(int) tftpAddOptionToOACK(PNATState pData, struct mbuf *pMBuf, const char *pszOptName, uint16_t u16OptValue)
     531DECLINLINE(int) tftpAddOptionToOACK(PNATState pData, struct mbuf *pMBuf, const char *pszOptName, uint64_t u64OptValue)
    527532{
    528533    char aszOptionBuffer[256];
     
    530535    int rc = VINF_SUCCESS;
    531536    int cbMBufCurrent = pMBuf->m_len;
    532     LogFlowFunc(("pMBuf:%p, pszOptName:%s, u16OptValue:%u\n", pMBuf, pszOptName, u16OptValue));
     537    LogFlowFunc(("pMBuf:%p, pszOptName:%s, u16OptValue:%ld\n", pMBuf, pszOptName, u64OptValue));
    533538    AssertPtrReturn(pMBuf, VERR_INVALID_PARAMETER);
    534539    AssertPtrReturn(pszOptName, VERR_INVALID_PARAMETER);
     
    536541    RT_ZERO(aszOptionBuffer);
    537542    iOptLength += RTStrPrintf(aszOptionBuffer, 256 , "%s", pszOptName) + 1;
    538     iOptLength += RTStrPrintf(aszOptionBuffer + iOptLength, 256 - iOptLength , "%u", u16OptValue) + 1;
     543    iOptLength += RTStrPrintf(aszOptionBuffer + iOptLength, 256 - iOptLength , "%u", u64OptValue) + 1;
    539544    if (iOptLength > M_TRAILINGSPACE(pMBuf))
    540545        rc = VERR_BUFFER_OVERFLOW; /* buffer too small */
     
    578583
    579584    if (pTftpSession->OptionBlkSize.fRequested)
    580         rc = tftpAddOptionToOACK(pData, m, "blksize", pTftpSession->OptionBlkSize.u16Value);
    581     else if (pTftpSession->OptionSize.fRequested)
    582         rc = tftpAddOptionToOACK(pData, m, "size", pTftpSession->OptionSize.u16Value);
    583     else if (pTftpSession->OptionTSize.fRequested)
    584         rc = tftpAddOptionToOACK(pData, m, "tsize", pTftpSession->OptionTSize.u16Value);
     585    {
     586        if (pTftpSession->OptionBlkSize.u64Value > UINT16_MAX)
     587            return -1;
     588        else
     589            rc = tftpAddOptionToOACK(pData, m, "blksize", pTftpSession->OptionBlkSize.u64Value);
     590    }
     591    if (pTftpSession->OptionTSize.fRequested)
     592        rc = tftpAddOptionToOACK(pData, m, "tsize", pTftpSession->OptionTSize.u64Value);
    585593
    586594    rc = tftpSend(pData, pTftpSession, m, pcTftpIpHeaderRecv);
     
    597605    PTFTPIPHDR pTftpIpHeader = NULL;
    598606
     607    LogFlowFunc(("ENTER: errorcode: %RX16, msg: %s\n", errorcode, msg));
    599608    m = slirpTftpMbufAlloc(pData);
    600609    if (!m)
     610    {
     611        LogFlowFunc(("LEAVE: Can't allocate mbuf\n"));
    601612        return -1;
     613    }
    602614
    603615    m->m_data += if_maxlinkhdr;
     
    616628    tftpSessionTerminate(pTftpSession);
    617629
     630    LogFlowFuncLeave();
    618631    return 0;
    619632}
     
    626639    struct mbuf *m;
    627640    PTFTPIPHDR pTftpIpHeader;
    628     int cbRead;
     641    int cbRead = 0;
    629642    int rc = VINF_SUCCESS;
    630643
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