VirtualBox

Ignore:
Timestamp:
Jan 11, 2019 4:36:34 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
128112
Message:

NAT: clamp tftp block size to 1428 to simplify things.

File:
1 edited

Legend:

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

    r76775 r76782  
    274274    while (cbTftpRRQRaw)
    275275    {
    276         idxTftpRRQRaw = RTStrNLen(pszTftpRRQRaw, 512 - idxTftpRRQRaw) + 1;
     276        rc = RTStrNLenEx(pszTftpRRQRaw, cbTftpRRQRaw, &idxTftpRRQRaw);
     277        if (RT_SUCCESS(rc))
     278            ++idxTftpRRQRaw;    /* count the NUL too */
     279        else
     280            break;
     281
    277282        if (RTStrNLen((char *)pTftpSession->pszFilename, TFTP_FILENAME_MAX) == 0)
    278283        {
     
    300305        {
    301306            if (!RTStrICmp("blksize", g_TftpDesc[idxOptionArg].pszName))
    302             {
    303307                rc = tftpSessionParseAndMarkOption(pszTftpRRQRaw, &pTftpSession->OptionBlkSize);
    304                 if (pTftpSession->OptionBlkSize.u64Value > UINT16_MAX)
    305                     rc = VERR_INVALID_PARAMETER;
    306             }
    307308
    308309            if (   RT_SUCCESS(rc)
     
    455456    }
    456457
     458    int cOptions = 0;
     459
    457460    if (pTftpSession->OptionTSize.fRequested)
    458461    {
    459462        pTftpSession->OptionTSize.u64Value = cbSessionFile;
    460     }
    461     if (   !pTftpSession->OptionBlkSize.u64Value
    462         && !pTftpSession->OptionBlkSize.fRequested)
    463     {
    464         pTftpSession->OptionBlkSize.u64Value = 1428;
    465     }
     463        ++cOptions;
     464    }
     465
     466    if (pTftpSession->OptionBlkSize.fRequested)
     467    {
     468        if (pTftpSession->OptionBlkSize.u64Value < 8)
     469        {
     470            /*
     471             * we cannot make a counter-offer larger than the client's
     472             * value, so just pretend we didn't recognize it and use
     473             * default block size
     474             */
     475            pTftpSession->OptionBlkSize.fRequested = 0;
     476            pTftpSession->OptionBlkSize.u64Value = 512;
     477        }
     478        else if (pTftpSession->OptionBlkSize.u64Value > 1428)
     479        {
     480            pTftpSession->OptionBlkSize.u64Value = 1428;
     481            ++cOptions;
     482        }
     483    }
     484    else
     485    {
     486        pTftpSession->OptionBlkSize.u64Value = 512;
     487    }
     488
     489    rc = cOptions > 0 ? VINF_SUCCESS : VWRN_NOT_FOUND;
    466490    LogFlowFuncLeaveRC(rc);
    467491    return rc;
     
    506530    AssertPtrReturn(pu8Data, VERR_INVALID_PARAMETER);
    507531    AssertPtrReturn(pcbReadData, VERR_INVALID_PARAMETER);
    508     AssertReturn(pcTftpSession->OptionBlkSize.u64Value < UINT16_MAX, VERR_INVALID_PARAMETER);
    509532    LogFlowFunc(("pcTftpSession:%p, pu8Data:%p, pcbReadData:%p\n",
    510533                    pcTftpSession,
     
    602625
    603626    if (pTftpSession->OptionBlkSize.fRequested)
    604     {
    605         if (pTftpSession->OptionBlkSize.u64Value > UINT16_MAX)
    606             rc = VERR_INVALID_PARAMETER;
    607         else
    608             rc = tftpAddOptionToOACK(pData, m, "blksize", pTftpSession->OptionBlkSize.u64Value);
    609     }
     627        rc = tftpAddOptionToOACK(pData, m, "blksize", pTftpSession->OptionBlkSize.u64Value);
     628
    610629    if (   RT_SUCCESS(rc)
    611630        && pTftpSession->OptionTSize.fRequested)
     
    683702    pTftpIpHeader->Core.u16TftpOpCode = RT_H2N_U16(pTftpSession->cTftpAck);
    684703
    685     rc = tftpReadDataBlock(pData, pTftpSession, (uint8_t *)&pTftpIpHeader->Core.u16TftpOpCode + sizeof(uint16_t), &cbRead);
     704    if (RT_LIKELY(M_TRAILINGSPACE(m) >= pTftpSession->OptionBlkSize.u64Value))
     705    {
     706        uint8_t *pu8Data = (uint8_t *)&pTftpIpHeader->Core.u16TftpOpCode + sizeof(uint16_t);
     707        rc = tftpReadDataBlock(pData, pTftpSession, pu8Data, &cbRead);
     708    }
     709    else
     710        rc = VERR_BUFFER_OVERFLOW;
    686711
    687712    if (RT_SUCCESS(rc))
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