From f36faef417707b5a4a635d6555e870baa5402850 Mon Sep 17 00:00:00 2001 From: Dylan Mikus Date: Thu, 3 Dec 2015 15:26:47 +0000 Subject: [PATCH] Code bug fixes and safety checks around error-possible code. Fixes and changes: - Only create the metadata file if the call is being recorded. - Only write to the metadata file if we actually created it (NULL check). - Make sure we have metadata before putting it on the call object - Correctly overwrite recording metadata without leaking memory - Set the no kernalization flag per call instead of for *every* packet. - Logging cleanup. --- daemon/call.c | 4 +--- daemon/call.h | 2 +- daemon/call_interfaces.c | 16 ++++++++++------ daemon/media_socket.c | 8 +------- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index 4de0125c6..0edaee551 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -1527,7 +1527,7 @@ int monologue_offer_answer(struct call_monologue *other_ml, GQueue *streams, ml_media = other_ml_media = NULL; str *pcap_path = setup_recording_file(call, monologue); - if (pcap_path != NULL) { + if (pcap_path != NULL && call->meta_fp != NULL) { fprintf(call->meta_fp, "%s\n", pcap_path->s); } @@ -2331,8 +2331,6 @@ static struct call *call_create(const str *callid, struct callmaster *m) { c->dtls_cert = dtls_cert(); c->tos = m->conf.default_tos; - setup_meta_file(c); - return c; } diff --git a/daemon/call.h b/daemon/call.h index f1faa8873..375fa75f1 100644 --- a/daemon/call.h +++ b/daemon/call.h @@ -147,7 +147,7 @@ enum call_type { #define PS_FLAG_CONFIRMED 0x00200000 #define PS_FLAG_KERNELIZED 0x00400000 #define PS_FLAG_NO_KERNEL_SUPPORT 0x00800000 -#define PS_FLAG_FORCE_DAEMON_MODE 0x01000000 +#define PS_FLAG_UNUSED 0x01000000 #define PS_FLAG_FINGERPRINT_VERIFIED 0x02000000 #define PS_FLAG_STRICT_SOURCE SHARED_FLAG_STRICT_SOURCE #define PS_FLAG_MEDIA_HANDOVER SHARED_FLAG_MEDIA_HANDOVER diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index b9474a832..c69407c5b 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -354,7 +354,7 @@ str *call_lookup_tcp(char **out, struct callmaster *m) { str *call_delete_udp(char **out, struct callmaster *m) { str callid, branch, fromtag, totag; - __C_DBG("got delete for callid '%s' and viabranch '%s'", + __C_DBG("got delete for callid '%s' and viabranch '%s'", out[RE_UDP_DQ_CALLID], out[RE_UDP_DQ_VIABRANCH]); str_init(&callid, out[RE_UDP_DQ_CALLID]); @@ -684,15 +684,20 @@ static const char *call_offer_answer_ng(bencode_item_t *input, struct callmaster call = call_get_opmode(&callid, m, opmode); - bencode_dictionary_get_str(input, "metadata", &metadata); - call->metadata = str_dup(&metadata); - errstr = "Unknown call-id"; if (!call) goto out; if (recordcall.s && !str_cmp(&recordcall, "yes")) { - call->record_call = 1; + if (!call->record_call) { + setup_meta_file(call); + call->record_call = 1; + } + bencode_dictionary_get_str(input, "metadata", &metadata); + if (metadata.len > 0) { + free(call->metadata); + call->metadata = str_dup(&metadata); + } } else { call->record_call = 0; } @@ -748,7 +753,6 @@ static const char *call_offer_answer_ng(bencode_item_t *input, struct callmaster GList *l; char *recording_path; for (l = call->recording_pcaps; l; l = l->next) { - ilog(LOG_INFO, "xxegreen: Recording path %s", l->data); bencode_list_add_string(recordings, l->data); } diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 9e9ef52bc..03bd6546d 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -834,9 +834,7 @@ void kernelize(struct packet_stream *stream) { struct packet_stream *sink = NULL; const char *nk_warn_msg; - if (PS_ISSET(stream, KERNELIZED)) - return; - if (PS_ISSET(stream, FORCE_DAEMON_MODE)) + if (PS_ISSET(stream, KERNELIZED) || call->record_call) return; if (cm->conf.kernelid < 0) goto no_kernel; @@ -942,8 +940,6 @@ void __unkernelize(struct packet_stream *p) { return; if (PS_ISSET(p, NO_KERNEL_SUPPORT)) return; - if (PS_ISSET(p, FORCE_DAEMON_MODE)) - return; if (p->call->callmaster->conf.kernelfd >= 0) { __re_address_translate_ep(&rea, &p->selected_sfd->socket.local); @@ -1186,8 +1182,6 @@ loop_ok: // If recording pcap dumper is set, then we record the call. if (recording_pdumper != NULL) { stream_pcap_dump(recording_pdumper, s); - // EGREEN: This is going to happen for every packet. We need to do better - PS_SET(stream, FORCE_DAEMON_MODE); } if (handler_ret >= 0) {