VirtualBox

Ignore:
Timestamp:
Dec 26, 2018 2:12:14 AM (6 years ago)
Author:
vboxsync
Message:

x11/vboxvideo/getmode.c: Recent GCC correctly points out possible trunction when using strncat with a 53 char destination buffer and a 256 char source string. Attempted to placate it, hoping the code still works...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/vboxvideo/getmode.c

    r69346 r76480  
    261261void vbvxSetUpLinuxACPI(ScreenPtr pScreen)
    262262{
     263    static const char s_szDevInput[] = "/dev/input/";
     264    struct dirent *pDirent;
     265    char szFile[sizeof(s_szDevInput) + sizeof(pDirent->d_name) + 16];
    263266    VBOXPtr pVBox = VBOXGetRec(xf86Screens[pScreen->myNum]);
    264     struct dirent *pDirent;
    265267    DIR *pDir;
    266268    int fd = -1;
     
    271273    if (pDir == NULL)
    272274        return;
     275    memcpy(szFile, s_szDevInput, sizeof(s_szDevInput));
    273276    for (pDirent = readdir(pDir); pDirent != NULL; pDirent = readdir(pDir))
    274277    {
     
    276279        {
    277280#define BITS_PER_BLOCK (sizeof(unsigned long) * 8)
    278             char szFile[64] = "/dev/input/";
    279281            char szDevice[64] = "";
    280282            unsigned long afKeys[KEY_MAX / BITS_PER_BLOCK];
    281 
    282             strncat(szFile, pDirent->d_name, sizeof(szFile) - sizeof("/dev/input/"));
     283            size_t const cchName = strlen(pDirent->d_name);
     284            if (cchName + sizeof(s_szDevInput) > sizeof(szFile))
     285                continue;
     286            memcpy(&szFile[sizeof(s_szDevInput) - 1], pDirent->d_name, cchName + 1);
    283287            if (fd != -1)
    284288                close(fd);
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