RTP: fixed potential race condition

This commit is contained in:
Martin Pulec
2015-02-11 17:25:36 +01:00
parent a7f470b68a
commit f26844705f
3 changed files with 13 additions and 12 deletions

View File

@@ -508,9 +508,9 @@ static inline int udp_sendv4(socket_udp * s, struct iovec *vector, int count)
}
#endif // WIN32
static const char *udp_host_addr4(void)
static char *udp_host_addr4(void)
{
static char hname[MAXHOSTNAMELEN + 1];
char *hname = calloc(MAXHOSTNAMELEN + 1, 1);
struct hostent *hent;
struct in_addr iaddr;
@@ -526,7 +526,7 @@ static const char *udp_host_addr4(void)
assert(hent->h_addrtype == AF_INET);
memcpy(&iaddr.s_addr, hent->h_addr, sizeof(iaddr.s_addr));
strncpy(hname, inet_ntoa(iaddr), MAXHOSTNAMELEN);
return (const char *)hname;
return hname;
}
int udp_set_recv_buf(socket_udp *s, int size)
@@ -852,10 +852,10 @@ static int udp_sendv6(socket_udp * s, struct iovec *vector, int count)
}
#endif // WIN32
static const char *udp_host_addr6(socket_udp * s)
static char *udp_host_addr6(socket_udp * s)
{
#ifdef HAVE_IPv6
static char hname[MAXHOSTNAMELEN];
char *hname = calloc(MAXHOSTNAMELEN + 1, 1);
int gai_err, newsock;
struct addrinfo hints, *ai;
struct sockaddr_in6 local, addr6;
@@ -926,14 +926,14 @@ static const char *udp_host_addr6(socket_udp * s)
return NULL;
}
freeaddrinfo(ai);
return (const char *)hname;
return hname;
}
if (inet_ntop(AF_INET6, &local.sin6_addr, hname, MAXHOSTNAMELEN) ==
NULL) {
error_msg("inet_ntop: %s: \n", hname);
return NULL;
}
return (const char *)hname;
return hname;
#else /* HAVE_IPv6 */
UNUSED(s);
return "::"; /* The unspecified address... */
@@ -1329,9 +1329,9 @@ int udp_select_r(struct timeval *timeout, struct udp_fd_r * fd_struct)
* @s: UDP session.
*
* Return value: character string containing network address
* associated with session @s.
* associated with session @s. Returned value be freed by caller.
**/
const char *udp_host_addr(socket_udp * s)
char *udp_host_addr(socket_udp * s)
{
switch (s->mode) {
case IPv4:

View File

@@ -67,7 +67,7 @@ int udp_sendv(socket_udp *s, LPWSABUF vector, int count);
int udp_sendv(socket_udp *s, struct iovec *vector, int count);
#endif
const char *udp_host_addr(socket_udp *s);
char *udp_host_addr(socket_udp *s);
int udp_fd(socket_udp *s);
int udp_select(struct timeval *timeout);

View File

@@ -903,7 +903,7 @@ static double rtcp_interval(struct rtp *session)
static char *get_cname(socket_udp * s)
{
/* Set the CNAME. This is "user@hostname" or just "hostname" if the username cannot be found. */
const char *hname;
char *hname;
char *uname;
char *cname;
#ifndef WIN32
@@ -952,9 +952,10 @@ static char *get_cname(socket_udp * s)
if (hname == NULL) {
/* If we can't get our IP address we use the loopback address... */
/* This is horrible, but it stops the code from failing. */
hname = "127.0.0.1";
hname = strdup("127.0.0.1");
}
strncpy(cname + strlen(cname), hname, MAXCNAMELEN - strlen(cname));
free(hname);
return cname;
}