VirtualBox

Changeset 16653 in vbox for trunk/src/VBox/Devices/Network


Ignore:
Timestamp:
Feb 11, 2009 8:56:10 AM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
42639
Message:

NAT: fixed memmory corruption in new Unix multiplexing mechanism

Location:
trunk/src/VBox/Devices/Network
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/DrvNAT.cpp

    r16613 r16653  
    4343# ifndef RT_OS_WINDOWS
    4444#  include <unistd.h>
     45#  include <fcntl.h>
    4546#  include <poll.h>
    4647# endif
     
    350351    unsigned int cBreak = 0;
    351352# else
    352     struct pollfd *polls;
     353    struct pollfd *polls = NULL;
    353354# endif
    354355
     
    374375# ifndef RT_OS_WINDOWS
    375376        nFDs = slirp_get_nsock(pThis->pNATState);
    376         polls = (struct pollfd *)RTMemAllocZ((2 + nFDs) * sizeof(struct pollfd)); /* allocation for all sockets + ICMP and Management pipe*/
     377        polls = NULL;
     378        polls = (struct pollfd *)RTMemAlloc((1 + nFDs) * sizeof(struct pollfd) + sizeof(uint32_t)); /* allocation for all sockets + Management pipe*/
    377379        if (polls == NULL)
    378380        {
    379381            LogRel(("Can't allocate memory for polling\n"));
    380             AssertRelease(polls);
     382            return VERR_NO_MEMORY;
    381383        }
    382384
     
    386388        polls[0].fd = pThis->PipeRead;
    387389        polls[0].events = POLLRDNORM|POLLPRI|POLLRDBAND; /* POLLRDBAND usually doesn't used on Linux but seems used on Solaris */
    388         int cChangedFDs = poll(polls, nFDs + 2, ms ? ms : -1);
     390        polls[0].revents = 0;
     391
     392        int cChangedFDs = poll(polls, nFDs + 1, ms ? ms : -1);
     393        AssertRelease(cChangedFDs >= 0);
    389394        if (cChangedFDs >= 0)
    390395        {
    391             slirp_select_poll(pThis->pNATState, &polls[1], nFDs + 1);
     396            slirp_select_poll(pThis->pNATState, &polls[1], nFDs);
    392397            if (polls[0].revents & (POLLRDNORM|POLLPRI|POLLRDBAND))
    393398            {
  • trunk/src/VBox/Devices/Network/slirp/if.c

    r15890 r16653  
    186186    {
    187187        /* check if we can really output */
    188         if (!slirp_can_output(pData->pvUser)) 
     188        if (!slirp_can_output(pData->pvUser))
    189189        {
    190190            Log(("if_start: can't send\n"));
  • trunk/src/VBox/Devices/Network/slirp/ip_icmp.c

    r16614 r16653  
    101101    }
    102102    fd_nonblock(pData->icmp_socket.s);
     103    NSOCK_INC();
    103104#else /* RT_OS_WINDOWS */
    104105    pData->hmIcmpLibrary = LoadLibrary("Iphlpapi.dll");
  • trunk/src/VBox/Devices/Network/slirp/slirp.c

    r16612 r16653  
    3333#  define DO_UNIX_CHECK_FD_SET(so, events, fdset )  0 /*specific for Unix API */
    3434# else /* !VBOX_WITH_SIMPLIFIED_SLIRP_SYNC */
    35 #  define DO_ENGAGE_EVENT1(so, fdset, label)            \
    36     do {                                                \
    37         polls[poll_index].fd = (so)->s;                 \
    38         (so)->so_poll_index = poll_index;               \
    39         polls[poll_index].events = N_(fdset ## _poll);  \
    40         poll_index++;                                   \
     35#  define DO_ENGAGE_EVENT1(so, fdset, label)                    \
     36    do {                                                        \
     37        AssertRelease(poll_index < (nfds));                     \
     38        if(    so->so_poll_index != -1                          \
     39            && so->s == polls[so->so_poll_index].fd) {          \
     40            polls[poll_index].events |= N_(fdset ## _poll);     \
     41            break; /* out of this loop */                       \
     42        }                                                       \
     43        AssertRelease(poll_index >= 0 && poll_index < (nfds));  \
     44        polls[poll_index].fd = (so)->s;                         \
     45        (so)->so_poll_index = poll_index;                       \
     46        polls[poll_index].events = N_(fdset ## _poll);          \
     47        polls[poll_index].revents = 0;                          \
     48        poll_index++;                                           \
    4149    } while(0)
    4250
     
    4452#  define DO_ENGAGE_EVENT2(so, fdset1, fdset2, label)                           \
    4553    do {                                                                        \
     54        AssertRelease(poll_index < (nfds));                     \
     55        if(    so->so_poll_index != -1                          \
     56            && so->s == polls[so->so_poll_index].fd) {          \
     57            polls[poll_index].events |= N_(fdset1 ## _poll) | N_(fdset1 ## _poll);  \
     58            break; /* out of this loop */                       \
     59        }                                                       \
    4660        polls[poll_index].fd = (so)->s;                                         \
    4761        (so)->so_poll_index = poll_index;                                       \
     
    689703        QSOCKET_FOREACH(so, so_next, tcp)
    690704        /* { */
     705#if defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC) && !defined(RT_OS_WINDOWS)
     706            so->so_poll_index = -1;
     707#endif
    691708            STAM_COUNTER_INC(&pData->StatTCP);
    692709
     
    758775
    759776            STAM_COUNTER_INC(&pData->StatUDP);
     777#if defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC) && !defined(RT_OS_WINDOWS)
     778            so->so_poll_index = -1;
     779#endif
    760780
    761781            /*
     
    801821    *pnfds = VBOX_EVENT_COUNT;
    802822# else /* RT_OS_WINDOWS */
     823    AssertRelease(poll_index <= *pnfds);
    803824    *pnfds = poll_index;
    804825# endif /* !RT_OS_WINDOWS */
     
    924945
    925946            LOG_NAT_SOCK(so, TCP, &NetworkEvents, readfds, writefds, xfds);
     947
    926948
    927949            /*
     
    10891111                    so->so_state = SS_NOFDREF;
    10901112                    TCP_INPUT(pData, (struct mbuf *)NULL, sizeof(struct ip), so);
     1113                    CONTINUE(tcp);
    10911114                }
    10921115                /* Here should be other error handlings */
     1116                AssertRelease(!"shouldn't be here!!!");
    10931117            }
    10941118#endif
  • trunk/src/VBox/Devices/Network/slirp/socket.c

    r16571 r16653  
    6666        so->so_state = SS_NOFDREF;
    6767        so->s = -1;
     68#if defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC) && !defined(RT_OS_WINDOWS)
     69        so->so_poll_index = -1;
     70#endif
    6871    }
    6972    return so;
     
    8992#ifndef VBOX_WITH_SLIRP_MT
    9093    if(so->so_next && so->so_prev)
     94    {
    9195        remque(pData, so);  /* crashes if so is not in a queue */
    9296        NSOCK_DEC();
    93     so->so_state = SS_NOFDREF; /* for debugging purposes */
     97    }
    9498
    9599    RTMemFree(so);
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