diff --git a/daemon/call.c b/daemon/call.c index 2328039cc..3711beaa3 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -153,6 +153,7 @@ out: rwlock_unlock_w(&c->master_lock); rwlock_lock_r(&c->master_lock); + // coverity[missing_unlock : FALSE] return ret; } @@ -1515,10 +1516,18 @@ int monologue_offer_answer(struct call_monologue *other_ml, GQueue *streams, struct call_media *media, *other_media; unsigned int num_ports; unsigned int rr_calls_ports; - struct call_monologue *monologue = other_ml->active_dialogue; + struct call_monologue *monologue; struct endpoint_map *em; struct call *call; + /* we must have a complete dialogue, even though the to-tag (monologue->tag) + * may not be known yet */ + if (!other_ml) { + ilog(LOG_ERROR, "Incomplete dialogue association"); + return -1; + } + + monologue = other_ml->active_dialogue; call = monologue->call; call->last_signal = poller_now; @@ -1527,12 +1536,6 @@ int monologue_offer_answer(struct call_monologue *other_ml, GQueue *streams, // get the total number of ports needed for ALGORITHM_ROUND_ROBIN_CALLS algorithm rr_calls_ports = get_algorithm_num_ports(streams, ALGORITHM_ROUND_ROBIN_CALLS); - /* we must have a complete dialogue, even though the to-tag (monologue->tag) - * may not be known yet */ - if (!other_ml) { - ilog(LOG_ERROR, "Incomplete dialogue association"); - return -1; - } __C_DBG("this="STR_FORMAT" other="STR_FORMAT, STR_FMT(&monologue->tag), STR_FMT(&other_ml->tag)); __tos_change(call, flags); diff --git a/daemon/cli.c b/daemon/cli.c index f4d88999a..eab242b70 100644 --- a/daemon/cli.c +++ b/daemon/cli.c @@ -828,7 +828,7 @@ static void cli_incoming(int fd, void *p, uintptr_t u) { char* outbuf = replybuffer; const char* outbufend = replybuffer+BUFLENGTH; static const int MAXINPUT = 1024; - char inbuf[MAXINPUT]; + char inbuf[MAXINPUT+1]; int inlen = 0, readbytes = 0; int rc=0; @@ -850,7 +850,7 @@ next: ilog(LOG_INFO, "New cli connection from " DF, DP(sin)); do { - readbytes = read(nfd, inbuf+inlen, MAXINPUT); + readbytes = read(nfd, inbuf+inlen, MAXINPUT-inlen); if (readbytes == -1) { if (errno == EAGAIN || errno == EWOULDBLOCK) { ilog(LOG_INFO, "Could currently not read CLI commands. Reason:%s", strerror(errno)); diff --git a/daemon/control_ng.c b/daemon/control_ng.c index 661b06efc..05c96fa61 100644 --- a/daemon/control_ng.c +++ b/daemon/control_ng.c @@ -2,6 +2,7 @@ #include #include +#include #include "obj.h" #include "poller.h" @@ -125,8 +126,9 @@ static void control_ng_incoming(struct obj *obj, str *buf, const endpoint_t *sin return; } - bencode_buffer_init(&bencbuf); + assert( bencode_buffer_init(&bencbuf) == 0 ); resp = bencode_dictionary(&bencbuf); + assert(resp != NULL); cookie = *buf; cookie.len -= data.len; diff --git a/daemon/dtls.c b/daemon/dtls.c index 33d3e925c..8cd2d8ca8 100644 --- a/daemon/dtls.c +++ b/daemon/dtls.c @@ -127,6 +127,8 @@ static void buf_dump_free(char *buf, size_t len) { ilog(LOG_DEBUG, "--- %.*s", llen, p); + if (!f) + break; len -= llen + 1; p = f + 1; } diff --git a/daemon/graphite.c b/daemon/graphite.c index 0c08caf59..91a89c7c1 100644 --- a/daemon/graphite.c +++ b/daemon/graphite.c @@ -305,7 +305,7 @@ void graphite_loop_run(struct callmaster *cm, endpoint_t *graphite_ep, int secon next_run = g_now.tv_sec + seconds; if (graphite_sock.fd < 0 && connection_state == STATE_DISCONNECTED) { - rc = connect_to_graphite_server(graphite_ep); + connect_to_graphite_server(graphite_ep); } if (graphite_sock.fd >= 0 && connection_state == STATE_CONNECTED) { diff --git a/daemon/homer.c b/daemon/homer.c index 37442cd17..e9d49c881 100644 --- a/daemon/homer.c +++ b/daemon/homer.c @@ -478,7 +478,7 @@ static int send_hepv3 (GString *s, const str *id, int capt_id, const endpoint_t /* IPv6 */ else if(hg->ip_family.data == AF_INET6) { /* SRC IPv6 */ - memcpy((void*) buffer+buflen, &src_ip4, sizeof(struct hep_chunk_ip6)); + memcpy((void*) buffer+buflen, &src_ip6, sizeof(struct hep_chunk_ip6)); buflen += sizeof(struct hep_chunk_ip6); memcpy((void*) buffer+buflen, &dst_ip6, sizeof(struct hep_chunk_ip6)); @@ -552,8 +552,8 @@ static int send_hepv3 (GString *s, const str *id, int capt_id, const endpoint_t g_string_append_len(s, buffer, buflen); /* FREE */ - if(buffer) free(buffer); - if(hg) free(hg); + free(buffer); + free(hg); return 0; } diff --git a/daemon/ice.c b/daemon/ice.c index 1243610a2..b39ed3643 100644 --- a/daemon/ice.c +++ b/daemon/ice.c @@ -1009,7 +1009,7 @@ found: /* call(W) or call(R)+agent must be locked - no in_lock or out_lock must be held */ static int __check_valid(struct ice_agent *ag) { - struct call_media *media = ag->media; + struct call_media *media; struct packet_stream *ps; GList *l, *k, *m; GQueue all_compos; @@ -1022,6 +1022,8 @@ static int __check_valid(struct ice_agent *ag) { return 0; } + media = ag->media; + __get_complete_valid_pairs(&all_compos, ag); if (!all_compos.length) { diff --git a/daemon/kernel.c b/daemon/kernel.c index 479386b2c..0b17700ee 100644 --- a/daemon/kernel.c +++ b/daemon/kernel.c @@ -109,6 +109,7 @@ int kernel_add_stream(struct rtpengine_target_info *mti, int update) { msg.cmd = update ? REMG_UPDATE : REMG_ADD; msg.u.target = *mti; + // coverity[uninit_use_in_call : FALSE] ret = write(kernel.fd, &msg, sizeof(msg)); if (ret > 0) return 0; diff --git a/daemon/main.c b/daemon/main.c index 05322dd45..6b8ee4c8f 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -653,7 +653,7 @@ no_kernel: gettimeofday(&ctx->m->latest_graphite_interval_start, NULL); - timeval_from_us(&tmp_tv, graphite_interval*1000000); + timeval_from_us(&tmp_tv, (long long) graphite_interval*1000000); set_graphite_interval_tv(&tmp_tv); } diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 62c06adf9..6a6e4e9df 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -769,6 +769,8 @@ static void stream_fd_closed(int fd, void *p, uintptr_t u) { return; j = sizeof(i); + i = 0; + // coverity[check_return : FALSE] getsockopt(fd, SOL_SOCKET, SO_ERROR, &i, &j); ilog(LOG_WARNING, "Read error on media socket: %i (%s) -- closing call", i, strerror(i)); @@ -1328,7 +1330,7 @@ update_addr: /* check the destination address of the received packet against what we think our * local interface to use is */ - if (sfd && stream->selected_sfd && sfd != stream->selected_sfd) { + if (stream->selected_sfd && sfd != stream->selected_sfd) { ilog(LOG_INFO, "Switching local interface to %s", endpoint_print_buf(&sfd->socket.local)); stream->selected_sfd = sfd; update = 1; diff --git a/daemon/poller.c b/daemon/poller.c index d437e0f4f..9b0bbc694 100644 --- a/daemon/poller.c +++ b/daemon/poller.c @@ -96,7 +96,9 @@ static int __poller_add_item(struct poller *p, struct poller_item *i, int has_lo unsigned int u; struct epoll_event e; - if (!p || !i) + if (!p) + return -1; + if (!i) goto fail_lock; if (i->fd < 0) goto fail_lock; diff --git a/daemon/recording.c b/daemon/recording.c index 4bd854bb9..7c491e476 100644 --- a/daemon/recording.c +++ b/daemon/recording.c @@ -360,56 +360,59 @@ static int pcap_meta_finish_file(struct call *call) { struct recording *recording = call->recording; int return_code = 0; - if (recording != NULL && recording->pcap.meta_fp != NULL) { - // Print start timestamp and end timestamp - // YYYY-MM-DDThh:mm:ss - time_t start = call->created; - time_t end = g_now.tv_sec; - char timebuffer[20]; - struct tm *timeinfo; - timeinfo = localtime(&start); - strftime(timebuffer, 20, "%FT%T", timeinfo); - fprintf(recording->pcap.meta_fp, "\n\ncall start time: %s\n", timebuffer); - timeinfo = localtime(&end); - strftime(timebuffer, 20, "%FT%T", timeinfo); - fprintf(recording->pcap.meta_fp, "call end time: %s\n", timebuffer); - - // Print metadata - if (recording->metadata.len) - fprintf(recording->pcap.meta_fp, "\n\n"STR_FORMAT"\n", STR_FMT(&recording->metadata)); - fclose(recording->pcap.meta_fp); - - // Get the filename (in between its directory and the file extension) - // and move it to the finished file location. - // Rename extension to ".txt". - int fn_len; - char *meta_filename = strrchr(recording->meta_filepath, '/'); - char *meta_ext = NULL; - if (meta_filename == NULL) { - meta_filename = recording->meta_filepath; - } - else { - meta_filename = meta_filename + 1; - } - // We can always expect a file extension - meta_ext = strrchr(meta_filename, '.'); - fn_len = meta_ext - meta_filename; - int prefix_len = strlen(spooldir) + 10; // constant for "/metadata/" suffix - int ext_len = 4; // for ".txt" - char new_metapath[prefix_len + fn_len + ext_len + 1]; - snprintf(new_metapath, prefix_len+fn_len+1, "%s/metadata/%s", spooldir, meta_filename); - snprintf(new_metapath + prefix_len+fn_len, ext_len+1, ".txt"); - return_code = return_code || rename(recording->meta_filepath, new_metapath); - if (return_code != 0) { - ilog(LOG_ERROR, "Could not move metadata file \"%s\" to \"%s/metadata/\"", - recording->meta_filepath, spooldir); - } else { - ilog(LOG_INFO, "Moved metadata file \"%s\" to \"%s/metadata\"", - recording->meta_filepath, spooldir); - } - } else { + if (recording == NULL || recording->pcap.meta_fp == NULL) { ilog(LOG_INFO, "Trying to clean up recording meta file without a file pointer opened."); + return 0; + } + + // Print start timestamp and end timestamp + // YYYY-MM-DDThh:mm:ss + time_t start = call->created; + time_t end = g_now.tv_sec; + char timebuffer[20]; + struct tm *timeinfo; + timeinfo = localtime(&start); + strftime(timebuffer, 20, "%FT%T", timeinfo); + fprintf(recording->pcap.meta_fp, "\n\ncall start time: %s\n", timebuffer); + timeinfo = localtime(&end); + strftime(timebuffer, 20, "%FT%T", timeinfo); + fprintf(recording->pcap.meta_fp, "call end time: %s\n", timebuffer); + + // Print metadata + if (recording->metadata.len) + fprintf(recording->pcap.meta_fp, "\n\n"STR_FORMAT"\n", STR_FMT(&recording->metadata)); + fclose(recording->pcap.meta_fp); + recording->pcap.meta_fp = NULL; + + // Get the filename (in between its directory and the file extension) + // and move it to the finished file location. + // Rename extension to ".txt". + int fn_len; + char *meta_filename = strrchr(recording->meta_filepath, '/'); + char *meta_ext = NULL; + if (meta_filename == NULL) { + meta_filename = recording->meta_filepath; } + else { + meta_filename = meta_filename + 1; + } + // We can always expect a file extension + meta_ext = strrchr(meta_filename, '.'); + fn_len = meta_ext - meta_filename; + int prefix_len = strlen(spooldir) + 10; // constant for "/metadata/" suffix + int ext_len = 4; // for ".txt" + char new_metapath[prefix_len + fn_len + ext_len + 1]; + snprintf(new_metapath, prefix_len+fn_len+1, "%s/metadata/%s", spooldir, meta_filename); + snprintf(new_metapath + prefix_len+fn_len, ext_len+1, ".txt"); + return_code = return_code || rename(recording->meta_filepath, new_metapath); + if (return_code != 0) { + ilog(LOG_ERROR, "Could not move metadata file \"%s\" to \"%s/metadata/\"", + recording->meta_filepath, spooldir); + } else { + ilog(LOG_INFO, "Moved metadata file \"%s\" to \"%s/metadata\"", + recording->meta_filepath, spooldir); + } + mutex_destroy(&recording->pcap.recording_lock); return return_code; diff --git a/daemon/rtcp.c b/daemon/rtcp.c index 1399a5d36..0c5921869 100644 --- a/daemon/rtcp.c +++ b/daemon/rtcp.c @@ -726,8 +726,6 @@ void parse_and_log_rtcp_report(struct stream_fd *sfd, const str *ori_s, const en json = NULL; } - if (json) - g_string_free(json, TRUE); if (log) g_string_free(log, TRUE); } diff --git a/daemon/sdp.c b/daemon/sdp.c index a8a6f499f..520b783e6 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -490,7 +490,7 @@ static int parse_attribute_crypto(struct sdp_attribute *output) { if (c->lifetime_str.len >= 3 && !memcmp(c->lifetime_str.s, "2^", 2)) { c->lifetime = strtoull(c->lifetime_str.s + 2, NULL, 10); err = "invalid key lifetime"; - if (!c->lifetime || c->lifetime > 64) + if (!c->lifetime || c->lifetime >= 64) goto error; c->lifetime = 1ULL << c->lifetime; } @@ -889,6 +889,10 @@ int sdp_parse(str *body, GQueue *sessions) { line_end--; } + errstr = "SDP doesn't start with a session definition"; + if (!session && b[0] != 'v') + goto error; + switch (b[0]) { case 'v': errstr = "Error in v= line"; @@ -1001,7 +1005,7 @@ int sdp_parse(str *body, GQueue *sessions) { goto error; } - errstr = "SDP doesn't start with a session definition"; + errstr = "SDP doesn't start with a valid session definition"; if (!session) goto error; @@ -1304,8 +1308,7 @@ next: error: ilog(LOG_WARNING, "Failed to extract streams from SDP: %s", errstr); - if (sp) - g_slice_free1(sizeof(*sp), sp); + g_slice_free1(sizeof(*sp), sp); return -1; } @@ -1867,7 +1870,7 @@ static void insert_crypto(struct call_media *media, struct sdp_chopper *chop) { if (cp->mki_len) { ull = 0; for (i = 0; i < cp->mki_len && i < sizeof(ull); i++) - ull |= cp->mki[cp->mki_len - i - 1] << (i * 8); + ull |= (unsigned long long) cp->mki[cp->mki_len - i - 1] << (i * 8); chopper_append_printf(chop, "|%llu:%u", ull, cp->mki_len); } if (cp->session_params.unencrypted_srtp) diff --git a/daemon/socket.c b/daemon/socket.c index 2be848f7f..6e5b4c7ef 100644 --- a/daemon/socket.c +++ b/daemon/socket.c @@ -288,6 +288,7 @@ static ssize_t __ip_recvfrom_ts(socket_t *s, void *buf, size_t len, endpoint_t * if (cm->cmsg_level == SOL_SOCKET && cm->cmsg_type == SO_TIMESTAMP) { *tv = *((struct timeval *) CMSG_DATA(cm)); tv = NULL; + break; } } if (G_UNLIKELY(tv)) { diff --git a/daemon/socket.h b/daemon/socket.h index 569411de2..5694eed66 100644 --- a/daemon/socket.h +++ b/daemon/socket.h @@ -176,13 +176,16 @@ INLINE ssize_t socket_sendiov(socket_t *s, const struct iovec *v, unsigned int l /* XXX obsolete these? */ INLINE void nonblock(int fd) { + // coverity[check_return : FALSE] fcntl(fd, F_SETFL, O_NONBLOCK); } INLINE void reuseaddr(int fd) { int one = 1; + // coverity[check_return : FALSE] setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); } INLINE void ipv6only(int fd, int yn) { + // coverity[check_return : FALSE] setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yn, sizeof(yn)); } diff --git a/daemon/streambuf.c b/daemon/streambuf.c index 4b78b5613..24a7c241d 100644 --- a/daemon/streambuf.c +++ b/daemon/streambuf.c @@ -98,8 +98,10 @@ char *streambuf_getline(struct streambuf *b) { char *s = NULL; for (;;) { - if (s) + if (s) { free(s); + s = NULL; + } p = memchr(b->buf->str, '\n', b->buf->len); if (!p)