VirtualBox

Changeset 67757 in vbox for trunk/src/VBox/HostDrivers


Ignore:
Timestamp:
Jul 3, 2017 1:52:33 PM (8 years ago)
Author:
vboxsync
Message:

AdpCtl: bugref:8866: play safe and use snprintf()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/adpctl/VBoxNetAdpCtl.cpp

    r67687 r67757  
    320320                }
    321321            }
    322             pszBuffer = new char[strlen(pcszAddress) + 4]; // '/xx\0'
    323             sprintf(pszBuffer, "%s/%u", pcszAddress, cBits);
     322            const size_t cbBuf = strlen(pcszAddress) + 4;
     323            pszBuffer = new char[cbBuf]; // '/xx\0'
     324            snprintf(pszBuffer, cbBuf, "%s/%u", pcszAddress, cBits);
    324325            return pszBuffer;
    325326        }
     
    486487    int add(char *pszNameInOut);
    487488    int remove(const char *pcszName);
    488     int checkName(const char *pcszNameIn, char *pszNameOut);
     489    int checkName(const char *pcszNameIn, char *pszNameOut, size_t cbNameOut);
    489490protected:
    490491    virtual int doIOCtl(unsigned long iCmd, VBOXNETADPREQ *pReq);
     
    588589}
    589590
    590 int Adapter::checkName(const char *pcszNameIn, char *pszNameOut)
     591int Adapter::checkName(const char *pcszNameIn, char *pszNameOut, size_t cbNameOut)
    591592{
    592593    int iAdapterIndex = -1;
     
    599600        return ADPCTLERR_BAD_NAME;
    600601    }
    601     sprintf(pszNameOut, "vboxnet%d", iAdapterIndex);
     602    snprintf(pszNameOut, cbNameOut, "vboxnet%d", iAdapterIndex);
    602603    if (strcmp(pszNameOut, pcszNameIn))
    603604    {
     
    702703    }
    703704#endif
    704    
    705     rc = g_adapter.checkName(argv[1], szAdapterName);
     705
     706    rc = g_adapter.checkName(argv[1], szAdapterName, sizeof(szAdapterName));
    706707    if (rc)
    707708        return rc;
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