VirtualBox

Changeset 23048 in vbox for trunk/src


Ignore:
Timestamp:
Sep 15, 2009 11:21:32 PM (15 years ago)
Author:
vboxsync
Message:

VBoxNetAdpCtl.cpp: Fix for execv/dup2 failure path in the child.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/apps/adpctl/VBoxNetAdpCtl.cpp

    r23046 r23048  
    130130    if (pid == 0)
    131131    {
     132        /* child */
    132133        close(fds[0]);
    133134        close(STDOUT_FILENO);
     
    135136        if (rc >= 0)
    136137            execve(VBOXADPCTL_IFCONFIG_PATH, argv, envp);
    137     }
    138     else
    139     {
    140         close(fds[1]);
    141         FILE *fp = fdopen(fds[0], "r");
    142         if (!fp)
     138        return false;
     139    }
     140
     141    /* parent */
     142    close(fds[1]);
     143    FILE *fp = fdopen(fds[0], "r");
     144    if (!fp)
     145        return false;
     146
     147    int cAddrs;
     148    for (cAddrs = 0; cAddrs < MAX_ADDRESSES && fgets(szBuf, sizeof(szBuf), fp);)
     149    {
     150        int cbSkipWS = strspn(szBuf, " \t");
     151#if 0 /* Don't use this! assert() breaks the mac build. Use IPRT or be a rectangular building thing. */
     152        assert(cbSkipWS < 20);
     153#endif
     154        char *pszWord = strtok(szBuf + cbSkipWS, " ");
     155        /* We are concerned with IPv6 address lines only. */
     156        if (!pszWord || strcmp(pszWord, "inet6"))
     157            continue;
     158#ifdef RT_OS_LINUX
     159        pszWord = strtok(NULL, " ");
     160        /* Skip "addr:". */
     161        if (!pszWord || strcmp(pszWord, "addr:"))
     162            continue;
     163#endif
     164        pszWord = strtok(NULL, " ");
     165        /* Skip link-local addresses. */
     166        if (!pszWord || !strncmp(pszWord, "fe80", 4))
     167            continue;
     168        strncpy(aszAddresses[cAddrs++], pszWord, MAX_ADDRLEN-1);
     169    }
     170    fclose(fp);
     171
     172    for (int i = 0; i < cAddrs; i++)
     173    {
     174        if (executeIfconfig(pszAdapterName, "inet6",
     175                            VBOXADPCTL_DEL_CMD, aszAddresses[i]) != EXIT_SUCCESS)
    143176            return false;
    144 
    145         int cAddrs;
    146         for (cAddrs = 0; cAddrs < MAX_ADDRESSES && fgets(szBuf, sizeof(szBuf), fp);)
    147         {
    148             int cbSkipWS = strspn(szBuf, " \t");
    149 #if 0 /* Don't use this! assert() breaks the mac build. Use IPRT or be a rectangular building thing. */
    150             assert(cbSkipWS < 20);
    151 #endif
    152             char *pszWord = strtok(szBuf + cbSkipWS, " ");
    153             /* We are concerned with IPv6 address lines only. */
    154             if (!pszWord || strcmp(pszWord, "inet6"))
    155                 continue;
    156 #ifdef RT_OS_LINUX
    157             pszWord = strtok(NULL, " ");
    158             /* Skip "addr:". */
    159             if (!pszWord || strcmp(pszWord, "addr:"))
    160                 continue;
    161 #endif
    162             pszWord = strtok(NULL, " ");
    163             /* Skip link-local addresses. */
    164             if (!pszWord || !strncmp(pszWord, "fe80", 4))
    165                 continue;
    166             strncpy(aszAddresses[cAddrs++], pszWord, MAX_ADDRLEN-1);
    167         }
    168         fclose(fp);
    169 
    170         for (int i = 0; i < cAddrs; i++)
    171         {
    172             if (executeIfconfig(pszAdapterName, "inet6",
    173                                 VBOXADPCTL_DEL_CMD, aszAddresses[i]) != EXIT_SUCCESS)
    174                 return false;
    175         }
    176177    }
    177178
     
    191192    if (rc == -1)
    192193    {
    193         perror("VBoxNetAdpCtl: ioctl failed for " VBOXNETADP_CTL_DEV_NAME); 
     194        perror("VBoxNetAdpCtl: ioctl failed for " VBOXNETADP_CTL_DEV_NAME);
    194195        rc = ADPCTLERR_IOCTL_FAILED;
    195196    }
    196    
     197
    197198    close(fd);
    198  
     199
    199200    return rc;
    200201}
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