Skip to content

Commit

Permalink
Valgrind fixes for sockaddr structs (#1976)
Browse files Browse the repository at this point in the history
Avoid use of uninitialized members
  • Loading branch information
tmatth authored Mar 4, 2020
1 parent a6f0708 commit f3e1c1e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions ice.c
Original file line number Diff line number Diff line change
Expand Up @@ -858,8 +858,8 @@ int janus_ice_test_stun_server(janus_network_address *addr, uint16_t port,
return -1;
}
struct sockaddr *address = NULL, *remote = NULL;
struct sockaddr_in address4, remote4;
struct sockaddr_in6 address6, remote6;
struct sockaddr_in address4 = { 0 }, remote4 = { 0 };
struct sockaddr_in6 address6 = { 0 }, remote6 = { 0 };
socklen_t addrlen = 0;
if(addr->family == AF_INET) {
memset(&address4, 0, sizeof(address4));
Expand Down
4 changes: 2 additions & 2 deletions ip-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ int janus_network_detect_local_ip(janus_network_query_options addr_type, janus_n
int fd = -1;
if(addr_type == janus_network_query_options_ipv4 || addr_type == janus_network_query_options_any_ip) {
/* Let's try IPv4 (FIXME Should probably use other internal methods) */
struct sockaddr_in addr;
struct sockaddr_in addr = { 0 };
socklen_t len;
fd = socket(AF_INET, SOCK_DGRAM, 0);
if(fd > -1) {
Expand All @@ -290,7 +290,7 @@ int janus_network_detect_local_ip(janus_network_query_options addr_type, janus_n
fd = -1;
if(!found && (addr_type == janus_network_query_options_ipv6 || addr_type == janus_network_query_options_any_ip)) {
/* Let's try IPv6 (FIXME Should probably use other internal methods) */
struct sockaddr_in6 addr;
struct sockaddr_in6 addr = { 0 };
socklen_t len;
fd = socket(AF_INET6, SOCK_DGRAM, 0);
if(fd > -1) {
Expand Down
8 changes: 4 additions & 4 deletions plugins/janus_nosip.c
Original file line number Diff line number Diff line change
Expand Up @@ -1871,7 +1871,7 @@ char *janus_nosip_sdp_manipulate(janus_nosip_session *session, janus_sdp *sdp, g
}

static int janus_nosip_bind_socket(int fd, int port) {
struct sockaddr_in rtp_address;
struct sockaddr_in rtp_address = { 0 };
rtp_address.sin_family = AF_INET;
rtp_address.sin_port = htons(port);
inet_pton(AF_INET, local_ip, &rtp_address.sin_addr.s_addr);
Expand Down Expand Up @@ -2139,7 +2139,7 @@ static void *janus_nosip_relay_thread(void *data) {

/* File descriptors */
socklen_t addrlen;
struct sockaddr_in remote;
struct sockaddr_in remote = { 0 };
int resfd = 0, bytes = 0, pollerrs = 0;
struct pollfd fds[5];
int pipe_fd = session->media.pipefd[0];
Expand All @@ -2163,12 +2163,12 @@ static void *janus_nosip_relay_thread(void *data) {
session->media.updated = FALSE;

have_audio_server_ip = session->media.remote_audio_ip != NULL;
struct sockaddr_in audio_server_addr;
struct sockaddr_in audio_server_addr = { 0 };
memset(&audio_server_addr, 0, sizeof(struct sockaddr_in));
audio_server_addr.sin_family = AF_INET;

have_video_server_ip = session->media.remote_video_ip != NULL;
struct sockaddr_in video_server_addr;
struct sockaddr_in video_server_addr = { 0 };
memset(&video_server_addr, 0, sizeof(struct sockaddr_in));
video_server_addr.sin_family = AF_INET;

Expand Down
12 changes: 6 additions & 6 deletions plugins/janus_streaming.c
Original file line number Diff line number Diff line change
Expand Up @@ -4849,8 +4849,8 @@ static void *janus_streaming_handler(void *data) {
static int janus_streaming_create_fd(int port, in_addr_t mcast, const janus_network_address *iface,
const char *listenername, const char *medianame, const char *mountpointname, gboolean quiet) {
janus_mutex_lock(&fd_mutex);
struct sockaddr_in address;
struct sockaddr_in6 address6;
struct sockaddr_in address = { 0 };
struct sockaddr_in6 address6 = { 0 };
janus_network_address_string_buffer address_representation;

uint16_t rtp_port_next = rtp_range_slider; /* Read global slider */
Expand Down Expand Up @@ -5043,7 +5043,7 @@ static int janus_streaming_allocate_port_pair(const char *name, const char *medi

/* Helper to return fd port */
static int janus_streaming_get_fd_port(int fd) {
struct sockaddr_in6 server;
struct sockaddr_in6 server = { 0 };
socklen_t len = sizeof(server);
if(getsockname(fd, &server, &len) == -1) {
return -1;
Expand Down Expand Up @@ -6220,8 +6220,8 @@ static void janus_streaming_rtsp_latch(int fd, char *host, int port, struct sock
} else {
freeaddrinfo(res);
/* Prepare the recipient */
struct sockaddr_in remote4;
struct sockaddr_in6 remote6;
struct sockaddr_in remote4 = { 0 };
struct sockaddr_in6 remote6 = { 0 };
socklen_t addrlen = 0;
if(addr.family == AF_INET) {
memset(&remote4, 0, sizeof(remote4));
Expand Down Expand Up @@ -6254,7 +6254,7 @@ static int janus_streaming_rtsp_play(janus_streaming_rtp_source *source) {
if(source == NULL || source->curldata == NULL)
return -1;
/* First of all, send a latching packet to the RTSP server port(s) */
struct sockaddr_in6 remote;
struct sockaddr_in6 remote = { 0 };
if(source->remote_audio_port > 0 && source->audio_fd >= 0) {
JANUS_LOG(LOG_VERB, "RTSP audio latching: %s:%d\n", source->rtsp_ahost, source->remote_audio_port);
janus_streaming_rtsp_latch(source->audio_fd, source->rtsp_ahost,
Expand Down
2 changes: 1 addition & 1 deletion plugins/janus_videoroom.c
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,7 @@ static guint32 janus_videoroom_rtp_forwarder_add_helper(janus_videoroom_publishe
errno, strerror(errno));
return 0;
}
struct sockaddr_in6 address;
struct sockaddr_in6 address = { 0 };
socklen_t len = sizeof(address);
memset(&address, 0, sizeof(address));
address.sin6_family = AF_INET6;
Expand Down
4 changes: 2 additions & 2 deletions sctp.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ janus_sctp_association *janus_sctp_association_create(janus_dtls_srtp *dtls, jan

struct socket *sock = NULL;
unsigned int i = 0;
struct sockaddr_conn sconn;
struct sockaddr_conn sconn = { 0 };

/* Now go on with SCTP */
janus_sctp_channel *channel = NULL;
Expand Down Expand Up @@ -257,7 +257,7 @@ janus_sctp_association *janus_sctp_association_create(janus_dtls_srtp *dtls, jan

/* Operating as client */
JANUS_LOG(LOG_VERB, "[%"SCNu64"] Connecting the SCTP association\n", sctp->handle_id);
struct sockaddr_conn rconn;
struct sockaddr_conn rconn = { 0 };
memset(&rconn, 0, sizeof(struct sockaddr_conn));
rconn.sconn_family = AF_CONN;
rconn.sconn_port = htons(sctp->remote_port);
Expand Down
4 changes: 2 additions & 2 deletions transports/janus_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ static struct MHD_Daemon *janus_http_create_daemon(gboolean admin, char *path,
/* Any interface or IP address we need to limit ourselves to?
* NOTE WELL: specifying an interface does NOT bind to all IPs associated
* with that interface, but only to the first one that's detected */
static struct sockaddr_in addr;
struct sockaddr_in6 addr6;
static struct sockaddr_in addr = { 0 };
struct sockaddr_in6 addr6 = { 0 };
gboolean ipv6 = FALSE;
if(ip && strstr(ip, ":"))
ipv6 = TRUE;
Expand Down

0 comments on commit f3e1c1e

Please sign in to comment.