[Udpcast] bug in udpr-negotiate

Johan Gadsjö joga at kth.se
Wed Mar 8 14:01:36 CET 2006


Hi,

I have found a bug in udpr-negotiate.c resulting in a segmentation fault 
on my platform. I'm not sure if this list is the right place for bug 
reports and patches but I give it a try.

In function startReceiver the struct client_config is allocated on the 
stack. A pointer to this struct is later set globally 
(global_client_config). The problem with this is that the struct is freed 
as the function returns. client_config should initially have been 
allocated on the heap and not on the stack to allow this behavior.

Regards
Johan


A patch could look like this:

# diff udpcast-20060208/udpr-negotiate.c udpcast-modified/udpr-negotiate.c
84c84
<     struct client_config client_config;
---
>     struct client_config *client_config;
92c92,94
<     client_config.sender_is_newgen = 0;
---
>     client_config = MALLOC(struct client_config);
>
>     client_config->sender_is_newgen = 0;
113c115
<     zeroSockArray(client_config.socks, NR_CLIENT_SOCKS);
---
>     zeroSockArray(client_config->socks, NR_CLIENT_SOCKS);
115c117
<     client_config.S_UCAST = makeSocket(ADDR_TYPE_UCAST,
---
>     client_config->S_UCAST = makeSocket(ADDR_TYPE_UCAST,
118c120
<     client_config.S_BCAST = makeSocket(ADDR_TYPE_BCAST,
---
>     client_config->S_BCAST = makeSocket(ADDR_TYPE_BCAST,
126c128
<       setSocketToBroadcast(client_config.S_UCAST);
---
>       setSocketToBroadcast(client_config->S_UCAST);
132c134
<           setMcastDestination(client_config.S_UCAST, net_config->net_if,
---
>           setMcastDestination(client_config->S_UCAST, net_config->net_if,
134c136
<           setTtl(client_config.S_UCAST, net_config->ttl);
---
>           setTtl(client_config->S_UCAST, net_config->ttl);
136c138
<           client_config.S_MCAST_CTRL =
---
>           client_config->S_MCAST_CTRL =
148c150
<     printMyIp(net_config->net_if, client_config.S_UCAST);
---
>     printMyIp(net_config->net_if, client_config->S_UCAST);
154c156
<     client_config.clientNumber= 0; /*default number for asynchronous transfer*/
---
>     client_config->clientNumber= 0; /*default number for asynchronous transfer*/
161c163
<           if (sendConnectReq(&client_config, net_config,
---
>           if (sendConnectReq(client_config, net_config,
171c173
<       sock = udpc_selectSock(client_config.socks, NR_CLIENT_SOCKS);
---
>       sock = udpc_selectSock(client_config->socks, NR_CLIENT_SOCKS);
175c177
<                   Msg, client_config.serverAddr, net_config->portBase);
---
>                   Msg, client_config->serverAddr, net_config->portBase);
181c183
<       if(getPort(&client_config.serverAddr) !=
---
>       if(getPort(&client_config->serverAddr) !=
188c190
<               client_config.clientNumber = ntohl(Msg.connectReply.clNr);
---
>               client_config->clientNumber = ntohl(Msg.connectReply.clNr);
194c196
<                   client_config.sender_is_newgen = 1;
---
>                   client_config->sender_is_newgen = 1;
198c200
<               if (client_config.clientNumber == -1) {
---
>               if (client_config->clientNumber == -1) {
207c209
<                   client_config.sender_is_newgen = 1;
---
>                   client_config->sender_is_newgen = 1;
232,233c234,235
<                 client_config.clientNumber,
<                 getIpString(&client_config.serverAddr, ipBuffer));
---
>                 client_config->clientNumber,
>                 getIpString(&client_config->serverAddr, ipBuffer));
241c243
<       client_config.S_MCAST_DATA =
---
>       client_config->S_MCAST_DATA =
251,252c253,254
<       if(client_config.socks[i] != -1)
<         setRcvBuf(client_config.socks[i],net_config->requestedBufSize);
---
>       if(client_config->socks[i] != -1)
>         setRcvBuf(client_config->socks[i],net_config->requestedBufSize);
258c260
<     global_client_config= &client_config;
---
>     global_client_config= client_config;
268c270
<       client_config.isStarted = 0;
---
>       client_config->isStarted = 0;
272c274
<         client_config.console = NULL;
---
>         client_config->console = NULL;
276c278
<         client_config.console = prepareConsole(0);
---
>         client_config->console = prepareConsole(0);
280c282
<       spawnNetReceiver(&fifo,&client_config, net_config, stats);
---
>       spawnNetReceiver(&fifo,client_config, net_config, stats);
285c287
<       pthread_join(client_config.thread, NULL);
---
>       pthread_join(client_config->thread, NULL);




More information about the Udpcast mailing list