From: Jaroslav Kysela Date: Mon, 15 Jan 2018 14:47:53 +0000 (+0100) Subject: a bunch of coverity fixes X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1047c9026f5ccfb88080e4ca6a04cd46f7115a40;p=thirdparty%2Ftvheadend.git a bunch of coverity fixes --- diff --git a/src/api/api_epg.c b/src/api/api_epg.c index 30247378c..efe62ea15 100644 --- a/src/api/api_epg.c +++ b/src/api/api_epg.c @@ -161,7 +161,7 @@ api_epg_entry ( epg_broadcast_t *eb, const char *lang, access_t *perm, const cha } if (epnum.e_num) { htsmsg_add_u32(m, "episodeNumber", epnum.e_num); - if (epnum.s_cnt) + if (epnum.e_cnt) htsmsg_add_u32(m, "episodeCount", epnum.e_cnt); } if (epnum.p_num) { diff --git a/src/descrambler/capmt.c b/src/descrambler/capmt.c index b9148616e..dcce0d85e 100644 --- a/src/descrambler/capmt.c +++ b/src/descrambler/capmt.c @@ -1170,12 +1170,13 @@ capmt_send_key(capmt_t *capmt) const int index = capmt->capmt_last_key.index; const int parity = capmt->capmt_last_key.parity; const uint8_t *cw = capmt->capmt_last_key.cw; - ca_info_t *cai = &capmt->capmt_adapters[adapter].ca_info[index]; + ca_info_t *cai; int type; capmt->capmt_last_key.adapter = -1; if (adapter < 0) return; + cai = &capmt->capmt_adapters[adapter].ca_info[index]; switch (cai->algo) { case CA_ALGO_DVBCSA: type = DESCRAMBLER_CSA_CBC; @@ -1879,7 +1880,7 @@ capmt_thread(void *aux) la = (linuxdvb_adapter_t*)is->is_array[i]; if (!la || !la->la_is_enabled(la)) continue; n = la->la_dvb_number; - if (n < 0 || n > MAX_CA) { + if (n < 0 || n >= MAX_CA) { tvherror(LS_CAPMT, "%s: adapter number > MAX_CA", capmt_name(capmt)); continue; } @@ -1888,6 +1889,7 @@ capmt_thread(void *aux) &capmt->capmt_adapters[n].ca_sock, capmt->capmt_port + n); } + idnode_set_free(is); if (bind_ok) handle_ca0(capmt); } diff --git a/src/descrambler/descrambler.c b/src/descrambler/descrambler.c index 9d1abd91d..93438cd18 100644 --- a/src/descrambler/descrambler.c +++ b/src/descrambler/descrambler.c @@ -373,6 +373,7 @@ descrambler_service_start ( service_t *t ) } + pthread_mutex_lock(&t->s_stream_mutex); ((mpegts_service_t *)t)->s_dvb_mux->mm_descrambler_flush = 0; if (t->s_descramble == NULL) { t->s_descramble = dr = calloc(1, sizeof(th_descrambler_runtime_t)); @@ -399,6 +400,7 @@ descrambler_service_start ( service_t *t ) if (t->s_dvb_forcecaid == 0xffff) dr->dr_descramble = descrambler_pass; } + pthread_mutex_unlock(&t->s_stream_mutex); if (t->s_dvb_forcecaid != 0xffff) caclient_start(t); diff --git a/src/descrambler/dvbcam.c b/src/descrambler/dvbcam.c index 2b7313ff0..148c2f00d 100644 --- a/src/descrambler/dvbcam.c +++ b/src/descrambler/dvbcam.c @@ -180,7 +180,7 @@ dvbcam_register_cam(linuxdvb_ca_t * lca, uint16_t * caids, } if (ac == NULL) { if ((ac = calloc(1, sizeof(*ac))) == NULL) - return; + goto reterr; ac->ca = lca; } @@ -196,6 +196,7 @@ dvbcam_register_cam(linuxdvb_ca_t * lca, uint16_t * caids, if (ac_first == NULL) dvbcam_status_update(); +reterr: pthread_mutex_unlock(&dvbcam_mutex); } diff --git a/src/descrambler/emm_reass.c b/src/descrambler/emm_reass.c index b6db2e9ba..cd730ccb6 100644 --- a/src/descrambler/emm_reass.c +++ b/src/descrambler/emm_reass.c @@ -68,8 +68,10 @@ emm_conax if (data[0] == 0x82) { if (len >= 10) { PROVIDERS_FOREACH(ra, i, ep) - if (memcmp(&data[3], &ep->sa[1], 7) == 0) + if (memcmp(&data[3], &ep->sa[1], 7) == 0) { + match = 1; break; + } } } if (match) diff --git a/src/dvr/dvr_autorec.c b/src/dvr/dvr_autorec.c index 1c7978259..531d6a62e 100644 --- a/src/dvr/dvr_autorec.c +++ b/src/dvr/dvr_autorec.c @@ -846,9 +846,9 @@ dvr_autorec_entry_class_weekdays_rend(uint32_t weekdays, const char *lang) size_t l; int i; if (weekdays == 0x7f) - strcpy(buf + 1, tvh_gettext_lang(lang, N_("Every day"))); + snprintf(buf, sizeof(buf), "%s", tvh_gettext_lang(lang, N_("Every day"))); else if (weekdays == 0) - strcpy(buf + 1, tvh_gettext_lang(lang, N_("No days"))); + snprintf(buf, sizeof(buf), "%s", tvh_gettext_lang(lang, N_("No days"))); else { buf[0] = '\0'; for (i = 0; i < 7; i++) @@ -940,7 +940,7 @@ dvr_autorec_entry_class_star_rating_set(void *o, const void *v) { dvr_autorec_entry_t *dae = (dvr_autorec_entry_t *)o; const uint16_t *val = (uint16_t*)v; - if (*val < 0 || *val > 100) + if (*val > 100) return 0; dae->dae_star_rating = *val; return 1; diff --git a/src/dvr/dvr_db.c b/src/dvr/dvr_db.c index cb79609bc..3e8760595 100644 --- a/src/dvr/dvr_db.c +++ b/src/dvr/dvr_db.c @@ -1484,9 +1484,13 @@ static int _dvr_duplicate_unique_match(dvr_entry_t *de1, dvr_entry_t *de2, void * So reverse slash would find the char at id+12 so +1 for len * to include the slash itself. */ - const char *slash = strchr(progid1, '/'); - const ssize_t num_char = slash ? slash + 1 - progid1 : 0; - is_same_authority = !strncmp(progid1, progid2, num_char); + if (progid1 && progid2) { + const char *slash = strchr(progid1, '/'); + const ssize_t num_char = slash ? slash + 1 - progid1 : 0; + is_same_authority = !strncmp(progid1, progid2, num_char); + } else { + is_same_authority = 0; + } } const int do_progid_check = diff --git a/src/dvr/dvr_rec.c b/src/dvr/dvr_rec.c index ad05a3678..3de952724 100644 --- a/src/dvr/dvr_rec.c +++ b/src/dvr/dvr_rec.c @@ -405,16 +405,18 @@ _dvr_sub_scraper_friendly(const char *id, const char *fmt, const void *aux, char subtitle = NULL; } - char *title_buf = title ? alloca(strlen(title) + 1) : NULL; - char *subtitle_buf = subtitle ? alloca(strlen(subtitle) + 1) : NULL; + const size_t title_buf_size = title ? strlen(title) + 1 : 0; + char *title_buf = title ? alloca(title_buf_size) : NULL; + const size_t subtitle_buf_size = title ? strlen(title) + 1 : 0; + char *subtitle_buf = subtitle ? alloca(subtitle_buf_size) : NULL; /* Copy a cleaned version in to our buffers. * Since dvr_clean_directory_separator _can_ modify source if source!=dest * it means we have to remove our const when we call it. */ if (title) - dvr_clean_directory_separator((char*)title, title_buf, sizeof(title_buf)); + dvr_clean_directory_separator((char*)title, title_buf, title_buf_size); if (subtitle) - dvr_clean_directory_separator((char*)subtitle, subtitle_buf, sizeof(subtitle_buf)); + dvr_clean_directory_separator((char*)subtitle, subtitle_buf, subtitle_buf_size); int is_movie = 0; /* Override options on the format tag. This is useful because my OTA diff --git a/src/epg.c b/src/epg.c index 229476ba2..cf99a37e4 100644 --- a/src/epg.c +++ b/src/epg.c @@ -1299,7 +1299,8 @@ size_t epg_episode_number_format void epg_episode_get_epnum ( const epg_episode_t *ee, epg_episode_num_t *num ) { if (!ee || !num) { - memset(num, 0, sizeof(*num)); + if (num) + memset(num, 0, sizeof(*num)); return; } *num = ee->epnum; diff --git a/src/epggrab/module.c b/src/epggrab/module.c index 9ba1a277c..4dceab343 100644 --- a/src/epggrab/module.c +++ b/src/epggrab/module.c @@ -585,10 +585,10 @@ static void *_epggrab_socket_thread ( void *p ) epggrab_module_ext_t *mod = (epggrab_module_ext_t*)p; tvhinfo(mod->subsys, "%s: external socket enabled", mod->id); - while ( mod->enabled && (s1 = atomic_get(&mod->sock)) ) { + while (mod->enabled && (s1 = atomic_get(&mod->sock)) >= 0) { tvhdebug(mod->subsys, "%s: waiting for connection", mod->id); s = accept(s1, NULL, NULL); - if (s <= 0) continue; + if (s < 0) continue; tvhdebug(mod->subsys, "%s: got connection %d", mod->id, s); _epggrab_socket_handler(mod, s); close(s); @@ -608,7 +608,7 @@ epggrab_module_done_socket( void *m ) assert(mod->type == EPGGRAB_EXT); mod->active = 0; - sock = atomic_exchange(&mod->sock, 0); + sock = atomic_exchange(&mod->sock, -1); shutdown(sock, SHUT_RDWR); close(sock); if (mod->tid) { @@ -632,9 +632,10 @@ epggrab_module_activate_socket ( void *m, int a ) epggrab_module_ext_t *mod = (epggrab_module_ext_t*)m; const char *path; assert(mod->type == EPGGRAB_EXT); + int sock; /* Ignore */ - if ( mod->active == a ) return 0; + if (mod->active == a) return 0; /* Disable */ if (!a) { @@ -646,30 +647,29 @@ epggrab_module_activate_socket ( void *m, int a ) unlink(mod->path); // just in case! hts_settings_makedirs(mod->path); - atomic_set(&mod->sock, socket(AF_UNIX, SOCK_STREAM, 0)); - assert(atomic_get(&mod->sock)); + sock = socket(AF_UNIX, SOCK_STREAM, 0); + assert(sock >= 0); memset(&addr, 0, sizeof(struct sockaddr_un)); addr.sun_family = AF_UNIX; strncpy(addr.sun_path, mod->path, 100); - if ( bind(mod->sock, (struct sockaddr*)&addr, - sizeof(struct sockaddr_un)) != 0 ) { - tvherror(mod->subsys, "%s: failed to bind socket", mod->id); - close(mod->sock); - mod->sock = 0; + if (bind(sock, (struct sockaddr*)&addr, + sizeof(struct sockaddr_un)) != 0) { + tvherror(mod->subsys, "%s: failed to bind socket: %s", mod->id, strerror(errno)); + close(sock); return 0; } - if ( listen(mod->sock, 5) != 0 ) { - tvherror(mod->subsys, "%s: failed to listen on socket", mod->id); - close(mod->sock); - mod->sock = 0; + if (listen(mod->sock, 5) != 0) { + tvherror(mod->subsys, "%s: failed to listen on socket: %s", mod->id, strerror(errno)); + close(sock); return 0; } tvhdebug(mod->subsys, "%s: starting socket thread", mod->id); pthread_attr_init(&tattr); mod->active = 1; + atomic_set(&mod->sock, sock); tvhthread_create(&mod->tid, &tattr, _epggrab_socket_thread, mod, "epggrabso"); } return 1; @@ -689,6 +689,7 @@ epggrab_module_ext_t *epggrab_module_ext_create /* Allocate data */ if (!skel) skel = calloc(1, sizeof(epggrab_module_ext_t)); + atomic_set(&skel->sock, -1); /* Pass through */ hts_settings_buildpath(path, sizeof(path), "epggrab/%s.sock", sockid); diff --git a/src/htsmsg_binary2.c b/src/htsmsg_binary2.c index 5c5796642..a85aab81e 100644 --- a/src/htsmsg_binary2.c +++ b/src/htsmsg_binary2.c @@ -61,7 +61,6 @@ static inline uint8_t *htsmsg_binary2_set_length(uint8_t *p, uint32_t len) p[1] = 0x80 | (len >> 7); p[2] = len & 0x7f; return p + 3; - p += 2; } else if (len < 0x10000000) { p[0] = 0x80 | (len >> 21); p[1] = 0x80 | (len >> 14); diff --git a/src/htsp_server.c b/src/htsp_server.c index a330e4645..56da56222 100644 --- a/src/htsp_server.c +++ b/src/htsp_server.c @@ -1247,7 +1247,8 @@ htsp_build_event htsmsg_add_str(out, "method", method); htsmsg_add_u32(out, "eventId", e->id); - htsmsg_add_u32(out, "channelId", channel_get_id(e->channel)); + if (e->channel) + htsmsg_add_u32(out, "channelId", channel_get_id(e->channel)); htsmsg_add_s64(out, "start", e->start); htsmsg_add_s64(out, "stop", e->stop); if ((str = epg_broadcast_get_title(e, lang))) diff --git a/src/input/mpegts/dvb_psi.c b/src/input/mpegts/dvb_psi.c index 5fc522fd2..25927b98e 100644 --- a/src/input/mpegts/dvb_psi.c +++ b/src/input/mpegts/dvb_psi.c @@ -2261,7 +2261,7 @@ psi_desc_ca(mpegts_table_t *mt, mpegts_service_t *t, const uint8_t *buffer, int if (caid == 0x4ad2)//streamguard provid=0; if (caid != 0x4aee && caid != 0x4ad2) { // Bulcrypt - provid = size < 4 ? 0 : buffer[4]; + provid = size < 5 ? 0 : buffer[4]; } break; case 0x1800: // Nagra @@ -2445,7 +2445,7 @@ psi_parse_pmt case 0x06: /* 0x06 is Chinese Cable TV AC-3 audio track */ /* but mark it so only when no more descriptors exist */ - if (dllen > 1 || !mux || mux->mm_pmt_ac3 != MM_AC3_PMT_06) + if (dllen > 1 || mux->mm_pmt_ac3 != MM_AC3_PMT_06) break; /* fall through to SCT_AC3 */ case 0x81: diff --git a/src/input/mpegts/dvb_psi_hbbtv.c b/src/input/mpegts/dvb_psi_hbbtv.c index b13dee7e0..111576e9b 100644 --- a/src/input/mpegts/dvb_psi_hbbtv.c +++ b/src/input/mpegts/dvb_psi_hbbtv.c @@ -83,7 +83,7 @@ ts_recv_hbbtv_cb(mpegts_psi_table_t *mt, const uint8_t *buf, int len) case DVB_DESC_APP: l3 = *dptr++; dlen--; if (l3 % 5) goto dvberr; - while (l3 >= 5) { + while (dlen >= 5 && l3 >= 5) { tvhtrace(mt->mt_subsys, "%s: profile %04X %d.%d.%d", mt->mt_name, (dptr[0] << 8) | dptr[1], dptr[2], dptr[3], dptr[4]); dptr += 5; dlen -= 5; @@ -153,6 +153,7 @@ ts_recv_hbbtv_cb(mpegts_psi_table_t *mt, const uint8_t *buf, int len) htsmsg_add_msg(apps, NULL, map); } else { htsmsg_destroy(titles); + titles = NULL; } } if (l2 != 0) diff --git a/src/input/mpegts/en50221/en50221.c b/src/input/mpegts/en50221/en50221.c index 41a8406cb..5697600e1 100644 --- a/src/input/mpegts/en50221/en50221.c +++ b/src/input/mpegts/en50221/en50221.c @@ -727,7 +727,7 @@ static int en50221_create_app if (prop == NULL) tvherror(LS_EN50221, "%s: unknown resource id %08x", cil->cil_name, resource_id); - app = calloc(1, prop->ciap_struct_size); + app = calloc(1, prop ? prop->ciap_struct_size : 0); if (app == NULL) return -ENOMEM; snprintf(buf, sizeof(buf), "%s-app%08x/%04X", cil->cil_name, diff --git a/src/input/mpegts/en50221/en50221_apps.c b/src/input/mpegts/en50221/en50221_apps.c index ff12d85f6..8e8e17b19 100644 --- a/src/input/mpegts/en50221/en50221_apps.c +++ b/src/input/mpegts/en50221/en50221_apps.c @@ -209,6 +209,7 @@ en50221_app_ca_handle if (CICAM_CA_ENABLE(p[2]) != CICAM_CAEI_POSSIBLE) app->cia_ca_possible = 1; tvh_strlcatf(buf, sizeof(buf), c, " %d=%02X", u16, p[2]); + i -= 3; } } } diff --git a/src/input/mpegts/en50221/en50221_capmt.c b/src/input/mpegts/en50221/en50221_capmt.c index f84702f2a..e95d4619d 100644 --- a/src/input/mpegts/en50221/en50221_capmt.c +++ b/src/input/mpegts/en50221/en50221_capmt.c @@ -206,7 +206,7 @@ int en50221_capmt_build tl -= 2 + dlen; } if (l) - return -EINVAL; + goto reterr; y[3] = 0xf0; put_len12(y + 3, x - y - 5); } else { @@ -215,9 +215,11 @@ int en50221_capmt_build } } - *capmt = d; - *capmtlen = x - d; - return 0; + if (tl == 0) { + *capmt = d; + *capmtlen = x - d; + return 0; + } reterr: free(d); @@ -258,7 +260,7 @@ int en50221_capmt_build_query while (tl >= 5) { l = extract_len12(n + 3); if (l + 5 > tl) - return -EINVAL; + goto reterr; if (l > 0) { if (l < 7) goto reterr; @@ -268,11 +270,12 @@ int en50221_capmt_build_query n += 5 + l; tl -= 5 + l; } - if (tl) - return -EINVAL; - *dst = d; - *dstlen = capmtlen; - return 0; + + if (tl == 0) { + *dst = d; + *dstlen = capmtlen; + return 0; + } reterr: free(d); diff --git a/src/input/mpegts/iptv/iptv.c b/src/input/mpegts/iptv/iptv.c index 5707a2a22..aadd4b806 100644 --- a/src/input/mpegts/iptv/iptv.c +++ b/src/input/mpegts/iptv/iptv.c @@ -339,13 +339,15 @@ iptv_input_start_mux ( mpegts_input_t *mi, mpegts_mux_instance_t *mmi, int weigh pthread_mutex_lock(&iptv_lock); s = im->mm_iptv_url_raw; im->mm_iptv_url_raw = strdup(raw); - im->mm_active = mmi; // Note: must set here else mux_started call - // will not realise we're ready to accept pid open calls - ret = ih->start(im, im->mm_iptv_url_raw, &url); - if (!ret) - im->im_handler = ih; - else - im->mm_active = NULL; + if (im->mm_iptv_url_raw) { + im->mm_active = mmi; // Note: must set here else mux_started call + // will not realise we're ready to accept pid open calls + ret = ih->start(im, im->mm_iptv_url_raw, &url); + if (!ret) + im->im_handler = ih; + else + im->mm_active = NULL; + } pthread_mutex_unlock(&iptv_lock); urlreset(&url); diff --git a/src/input/mpegts/iptv/iptv_auto.c b/src/input/mpegts/iptv/iptv_auto.c index 2919d3b48..11b4a8ffd 100644 --- a/src/input/mpegts/iptv/iptv_auto.c +++ b/src/input/mpegts/iptv/iptv_auto.c @@ -343,12 +343,14 @@ iptv_auto_network_process_m3u(iptv_network_t *in, char *data, m = parse_m3u(data, in->in_ctx_charset, host_url); items = htsmsg_get_list(m, "items"); - HTSMSG_FOREACH(f, items) { - if ((item = htsmsg_field_get_map(f)) == NULL) continue; - iptv_auto_network_process_m3u_item(in, last_url, - remove_args, ignore_args, ignore_path, - chnum, item, &total, &count); - + if (items) { + HTSMSG_FOREACH(f, items) { + if ((item = htsmsg_field_get_map(f)) == NULL) continue; + iptv_auto_network_process_m3u_item(in, last_url, + remove_args, ignore_args, ignore_path, + chnum, item, &total, &count); + + } } htsmsg_destroy(m); if (total == 0) diff --git a/src/input/mpegts/iptv/iptv_http.c b/src/input/mpegts/iptv/iptv_http.c index cdb188b9b..21ae0819d 100644 --- a/src/input/mpegts/iptv/iptv_http.c +++ b/src/input/mpegts/iptv/iptv_http.c @@ -305,8 +305,10 @@ iptv_http_data } memcpy(hp->hls_aes128.tmp + hp->hls_aes128.tmp_len, buf, len); hp->hls_aes128.tmp_len += len; - if (off == im->mm_iptv_buffer.sb_ptr) + if (off == im->mm_iptv_buffer.sb_ptr) { + pthread_mutex_unlock(&iptv_lock); return 0; + } buf = im->mm_iptv_buffer.sb_data + im->mm_iptv_buffer.sb_ptr; len = im->mm_iptv_buffer.sb_ptr - off; assert((len % 16) == 0); diff --git a/src/input/mpegts/iptv/iptv_libav.c b/src/input/mpegts/iptv/iptv_libav.c index bd14b380e..35381e89d 100644 --- a/src/input/mpegts/iptv/iptv_libav.c +++ b/src/input/mpegts/iptv/iptv_libav.c @@ -178,6 +178,7 @@ iptv_libav_start ( iptv_mux_t *im, const char *raw, const url_t *url ) { iptv_libav_priv_t *la = calloc(1, sizeof(*la)); + assert(raw); pthread_mutex_init(&la->lock, NULL); im->im_opaque = la; if (strncmp(raw, "libav:", 6) == 0) @@ -191,7 +192,7 @@ iptv_libav_start ( iptv_mux_t *im, const char *raw, const url_t *url ) atomic_set(&la->pause, 0); sbuf_init(&la->sbuf); tvhthread_create(&la->thread, NULL, iptv_libav_thread, la, "libavinput"); - if (raw && raw[0]) + if (raw[0]) iptv_input_mux_started(im); return 0; } diff --git a/src/input/mpegts/iptv/iptv_mux.c b/src/input/mpegts/iptv/iptv_mux.c index 3129549f1..c796a4738 100644 --- a/src/input/mpegts/iptv/iptv_mux.c +++ b/src/input/mpegts/iptv/iptv_mux.c @@ -395,10 +395,11 @@ iptv_mux_create0 ( iptv_network_t *in, const char *uuid, htsmsg_t *conf ) htsmsg_add_u32(conf, "sid", in->in_service_id); htsmsg_add_u32(conf, "dvb_servicetype", 1); /* SDTV */ ms = iptv_service_create0(im, 0, 0, NULL, conf); - ms->s_pmt_pid = SERVICE_PMT_AUTO; htsmsg_destroy(conf); - if (ms) + if (ms) { + ms->s_pmt_pid = SERVICE_PMT_AUTO; mpegts_network_bouquet_trigger((mpegts_network_t *)in, 0); + } } htsmsg_destroy(c2); diff --git a/src/input/mpegts/linuxdvb/linuxdvb_ca.c b/src/input/mpegts/linuxdvb/linuxdvb_ca.c index d5055ae00..c70dba3a5 100644 --- a/src/input/mpegts/linuxdvb/linuxdvb_ca.c +++ b/src/input/mpegts/linuxdvb/linuxdvb_ca.c @@ -291,7 +291,7 @@ linuxdvb_ca_thread ( void *aux ) tvhtrace(LS_EN50221, "ca thread start"); ev = malloc(sizeof(*ev) * evsize); - poll = tvhpoll_create(ARRAY_SIZE(ev) + 1); + poll = tvhpoll_create(evsize + 1); tm = mclk(); waitms = 250; while (tvheadend_running && !quit) { @@ -1142,8 +1142,8 @@ linuxdvb_ca_enqueue_capmt if (!linuxdvb_ca_write_cmd(lca, CA_WRITE_CMD_CAPMT_QUERY, capmt2, capmtlen2)) { tvhtrace(LS_EN50221, "%s: CAPMT enqueued query (len %zd)", lca->lca_name, capmtlen2); en50221_capmt_dump(LS_EN50221, lca->lca_name, capmt2, capmtlen2); - free(capmt2); } + free(capmt2); } if (!linuxdvb_ca_write_cmd(lca, CA_WRITE_CMD_CAPMT, capmt, capmtlen)) { diff --git a/src/input/mpegts/linuxdvb/linuxdvb_frontend.c b/src/input/mpegts/linuxdvb/linuxdvb_frontend.c index 194dfa258..0e75259c6 100644 --- a/src/input/mpegts/linuxdvb/linuxdvb_frontend.c +++ b/src/input/mpegts/linuxdvb/linuxdvb_frontend.c @@ -1222,6 +1222,7 @@ linuxdvb_frontend_monitor ( void *aux ) sigstat.tc_bit = mmi->tii_stats.tc_bit; sigstat.ec_block = mmi->tii_stats.ec_block; sigstat.tc_block = mmi->tii_stats.tc_block; + memset(&sm, 0, sizeof(sm)); sm.sm_type = SMT_SIGNAL_STATUS; sm.sm_data = &sigstat; @@ -2069,6 +2070,13 @@ linuxdvb_frontend_create htsmsg_t *scconf; ssize_t r; + /* Internal config ID */ + snprintf(id, sizeof(id), "%s #%d", dvb_type2str(type), number); + if (conf) + conf = htsmsg_get_map(conf, id); + if (conf) + uuid = htsmsg_get_str(conf, "uuid"); + /* Tuner slave */ snprintf(id, sizeof(id), "master for #%d", number); if (conf && type == DVB_TYPE_S) { @@ -2077,13 +2085,6 @@ linuxdvb_frontend_create muuid = NULL; } - /* Internal config ID */ - snprintf(id, sizeof(id), "%s #%d", dvb_type2str(type), number); - if (conf) - conf = htsmsg_get_map(conf, id); - if (conf) - uuid = htsmsg_get_str(conf, "uuid"); - /* Fudge configuration for old network entry */ if (conf) { if (!htsmsg_get_list(conf, "networks") && diff --git a/src/input/mpegts/linuxdvb/linuxdvb_private.h b/src/input/mpegts/linuxdvb/linuxdvb_private.h index 0b6dcd597..3bb239260 100644 --- a/src/input/mpegts/linuxdvb/linuxdvb_private.h +++ b/src/input/mpegts/linuxdvb/linuxdvb_private.h @@ -525,7 +525,7 @@ htsmsg_t *linuxdvb_en50607_id_list ( void *o, const char *lang ); htsmsg_t *linuxdvb_en50494_pin_list ( void *o, const char *lang ); static inline int linuxdvb_unicable_is_en50607( const char *str ) - { return strcmp(str, UNICABLE_II_NAME) == 0; } + { return str && strcmp(str, UNICABLE_II_NAME) == 0; } static inline int linuxdvb_unicable_is_en50494( const char *str ) { return !linuxdvb_unicable_is_en50607(str); } diff --git a/src/input/mpegts/linuxdvb/linuxdvb_satconf.c b/src/input/mpegts/linuxdvb/linuxdvb_satconf.c index d62b7ab2b..9d6ede74e 100644 --- a/src/input/mpegts/linuxdvb/linuxdvb_satconf.c +++ b/src/input/mpegts/linuxdvb/linuxdvb_satconf.c @@ -1724,7 +1724,7 @@ linuxdvb_diseqc_raw_send for (i = 0; i < len; i++) { message.msg[i] = (uint8_t)va_arg(ap, int); if (tvhtrace_enabled()) - tvh_strlcatf(buf, sizeof(buf), c, "%02X ", message.msg[3 + i]); + tvh_strlcatf(buf, sizeof(buf), c, "%02X ", message.msg[i]); } va_end(ap); diff --git a/src/input/mpegts/mpegts_service.c b/src/input/mpegts/mpegts_service.c index 0a0a90490..a6946ac91 100644 --- a/src/input/mpegts/mpegts_service.c +++ b/src/input/mpegts/mpegts_service.c @@ -973,7 +973,7 @@ mpegts_service_raw_update_pids(mpegts_service_t *t, mpegts_apids_t *pids) pthread_mutex_lock(&t->s_stream_mutex); x = t->s_pids; t->s_pids = p; - if (!pids->all && x && x->all) { + if (pids && !pids->all && x && x->all) { mpegts_input_close_pid(mi, mm, MPEGTS_FULLMUX_PID, MPS_RAW, MPS_WEIGHT_RAW, t); mpegts_input_close_pids(mi, mm, t, 1); for (i = 0; i < x->count; i++) { @@ -981,7 +981,7 @@ mpegts_service_raw_update_pids(mpegts_service_t *t, mpegts_apids_t *pids) mpegts_input_open_pid(mi, mm, pi->pid, MPS_RAW, pi->weight, t, 0); } } else { - if (pids->all) { + if (pids && pids->all) { mpegts_input_close_pids(mi, mm, t, 1); mpegts_input_open_pid(mi, mm, MPEGTS_FULLMUX_PID, MPS_RAW, MPS_WEIGHT_RAW, t, 0); } else { diff --git a/src/input/mpegts/satip/satip_frontend.c b/src/input/mpegts/satip/satip_frontend.c index 0432f004a..43bda829b 100644 --- a/src/input/mpegts/satip/satip_frontend.c +++ b/src/input/mpegts/satip/satip_frontend.c @@ -149,6 +149,7 @@ satip_frontend_signal_cb( void *aux ) sigstat.ec_block = mmi->tii_stats.ec_block; sigstat.tc_block = mmi->tii_stats.tc_block; pthread_mutex_unlock(&mmi->tii_stats_mutex); + memset(&sm, 0, sizeof(sm)); sm.sm_type = SMT_SIGNAL_STATUS; sm.sm_data = &sigstat; LIST_FOREACH(svc, &mmi->mmi_mux->mm_transports, s_active_link) { @@ -2037,7 +2038,7 @@ new_tune: udp_multirecv_free(&um); lfe->sf_curmux = NULL; - memset(ev, 0, sizeof(&ev)); + memset(ev, 0, sizeof(ev)); nfds = 0; if ((rtsp_flags & SATIP_SETUP_TCP) == 0) { ev[nfds++].fd = rtp->fd; diff --git a/src/input/mpegts/tsdemux.c b/src/input/mpegts/tsdemux.c index 32d9ddd7a..0ef03d298 100644 --- a/src/input/mpegts/tsdemux.c +++ b/src/input/mpegts/tsdemux.c @@ -438,6 +438,7 @@ ts_flush(mpegts_service_t *t, sbuf_t *sb) pb = pktbuf_alloc(sb->sb_data, sb->sb_ptr); pb->pb_err = sb->sb_err; + memset(&sm, 0, sizeof(sm)); sm.sm_type = SMT_MPEGTS; sm.sm_data = pb; streaming_service_deliver((service_t *)t, streaming_msg_clone(&sm)); diff --git a/src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c b/src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c index eb2db76dc..d99be68d1 100644 --- a/src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c +++ b/src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c @@ -155,6 +155,7 @@ tvhdhomerun_frontend_input_thread ( void *aux ) pthread_mutex_unlock(&hfe->hf_hdhomerun_device_mutex); if(r < 1) { tvherror(LS_TVHDHOMERUN, "failed to set target: %d", r); + close(sockfd); return NULL; } @@ -293,6 +294,7 @@ tvhdhomerun_frontend_monitor_cb( void *aux ) sigstat.signal_scale = mmi->tii_stats.signal_scale = SIGNAL_STATUS_SCALE_RELATIVE; sigstat.ber = mmi->tii_stats.ber; sigstat.unc = atomic_get(&mmi->tii_stats.unc); + memset(&sm, 0, sizeof(sm)); sm.sm_type = SMT_SIGNAL_STATUS; sm.sm_data = &sigstat; diff --git a/src/libav.c b/src/libav.c index bab90a0b4..e87e2cd00 100644 --- a/src/libav.c +++ b/src/libav.c @@ -19,11 +19,12 @@ libav_log_callback(void *ptr, int level, const char *fmt, va_list vl) class_name = ptr && *(void **)ptr ? av_default_item_name(ptr) : ""; + if (fmt == NULL) + return; + l1 = strlen(fmt); l2 = strlen(class_name); fmt1 = alloca(l1 + l2 + 3); - if (fmt == NULL) - return; strcpy(fmt1, class_name); if (class_name[0]) diff --git a/src/misc/m3u.c b/src/misc/m3u.c index 75639da1d..e86abca79 100644 --- a/src/misc/m3u.c +++ b/src/misc/m3u.c @@ -240,6 +240,8 @@ multi: data = until_eol(data + 14); continue; } else if (strncmp(data, "#EXTVLCOPT:program=", 19) == 0) { + if (item == NULL) + item = htsmsg_create_map(); htsmsg_add_s64(item, "vlc-program", strtoll(data + 19, NULL, 10)); data = until_eol(data + 19); } else if (strncmp(data, "#EXT", 4) == 0) { diff --git a/src/satip/rtsp.c b/src/satip/rtsp.c index 631efbbeb..7641b85ce 100644 --- a/src/satip/rtsp.c +++ b/src/satip/rtsp.c @@ -197,7 +197,7 @@ rtsp_new_session(const char *ipstr, int delsys, uint32_t nsession, int session) } if (strcmp(rs->peer_ipstr, ipstr) == 0 && --count_u == 0) { tvhnotice(LS_SATIPS, "Max number (%i) of active RTSP sessions per user (IP: %s).", - satip_server_conf.satip_max_user_connections, strdup(ipstr)); + satip_server_conf.satip_max_user_connections, ipstr); return NULL; } } @@ -361,7 +361,7 @@ rtsp_conn_ip(http_connection_t *hc, char *buf, size_t buflen, int *port) used_port = rtsp_nat_port; } - if (used_ip[0] == '*' || used_ip[0] == '\0' || used_ip == NULL) { + if (used_ip == NULL || used_ip[0] == '*' || used_ip[0] == '\0') { if (local) { tcp_get_str_from_ip(hc->hc_local_ip, buf, buflen); used_ip = buf; @@ -514,8 +514,7 @@ static void rtsp_manage_descramble(session_t *rs) { idnode_set_t *found; - mpegts_service_t *s, *snext; - mpegts_service_t *master = (mpegts_service_t *)rs->subs->ths_raw_service; + mpegts_service_t *s, *snext, *master; slave_subscription_t *sub; mpegts_apids_t pmt_pids; size_t si; @@ -529,6 +528,8 @@ rtsp_manage_descramble(session_t *rs) if (rs->mux == NULL || rs->subs == NULL) goto end; + master = (mpegts_service_t *)rs->subs->ths_raw_service; + if (rs->pids.all) { LIST_FOREACH(s, &rs->mux->mm_services, s_dvb_mux_link) if (rtsp_validate_service(s, NULL)) diff --git a/src/spawn.c b/src/spawn.c index 13afa12ad..35fde1055 100644 --- a/src/spawn.c +++ b/src/spawn.c @@ -701,6 +701,9 @@ spawn_with_passthrough(const char *prog, char *argv[], char *envp[], // might have been spawned setpgid(p, p); } + // do not pass the local variable outside + if (argv[0] == bin) + argv[0] = NULL; return 0; } @@ -774,6 +777,9 @@ spawnv(const char *prog, char *argv[], pid_t *pid, int redir_stdout, int redir_s if (pid) *pid = p; + // do not pass the local variable outside + if (argv[0] == bin) + argv[0] = NULL; return 0; } diff --git a/src/transcoding/transcode/context.c b/src/transcoding/transcode/context.c index 098f05c7a..f333b32f5 100644 --- a/src/transcoding/transcode/context.c +++ b/src/transcoding/transcode/context.c @@ -272,20 +272,18 @@ tvh_context_pack(TVHContext *self, AVPacket *avpkt) if (self->helper && self->helper->pack) { pkt = self->helper->pack(self, avpkt); - } - else { + } else { pkt = pkt_alloc(self->stream->type, avpkt->data, avpkt->size, avpkt->pts, avpkt->dts, 0); } if (!pkt) { tvh_context_log(self, LOG_ERR, "failed to create packet"); + } else { + // FIXME: ugly hack + if (pkt->pkt_pcr == 0) + pkt->pkt_pcr = pkt->pkt_dts; + if (_context_meta(self, avpkt, pkt) || _context_wrap(self, avpkt, pkt)) + TVHPKT_CLEAR(pkt); } - else if (_context_meta(self, avpkt, pkt) || - _context_wrap(self, avpkt, pkt)) { - TVHPKT_CLEAR(pkt); - } - // FIXME: ugly hack - if (pkt->pkt_pcr == 0) - pkt->pkt_pcr = pkt->pkt_dts; return pkt; } diff --git a/src/uuid.c b/src/uuid.c index 258948be4..75a88773d 100644 --- a/src/uuid.c +++ b/src/uuid.c @@ -190,9 +190,9 @@ uuid_set_free ( tvh_uuid_set_t *us ) { if (us) { free(us->us_array); + us->us_size = 0; + us->us_count = 0; } - us->us_size = 0; - us->us_count = 0; } /* Destroy uuid set */ diff --git a/src/webui/simpleui.c b/src/webui/simpleui.c index 8f9107147..f2cc5fd54 100644 --- a/src/webui/simpleui.c +++ b/src/webui/simpleui.c @@ -206,7 +206,7 @@ page_simple(http_connection_t *hc, memset(&eq, 0, sizeof(eq)); eq.lang = strdup(lang); eq.fulltext = 1; - eq.stitle = s ? strdup(s) : NULL; + eq.stitle = strdup(s); //Note: force min/max durations for this interface to 0 and INT_MAX seconds respectively epg_query(&eq, hc->hc_access); diff --git a/src/webui/webui.c b/src/webui/webui.c index 6bac55e6f..7cf792df2 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -614,8 +614,7 @@ http_tag_playlist(http_connection_t *hc, int pltype, channel_tag_t *tag) htsbuf_queue_t *hq; char buf[255], ubuf[UUID_HEX_SIZE]; char *profile, *hostpath; - const char *name, *blank, *sort; - const char *lang = hc->hc_access->aa_lang_ui; + const char *name, *blank, *sort, *lang; channel_t *ch; channel_t **chlist; int idx, count = 0; @@ -624,6 +623,7 @@ http_tag_playlist(http_connection_t *hc, int pltype, channel_tag_t *tag) access_verify2(hc->hc_access, ACCESS_STREAMING)) return HTTP_STATUS_UNAUTHORIZED; + lang = hc->hc_access->aa_lang_ui; hq = &hc->hc_reply; profile = profile_validate_name(http_arg_get(&hc->hc_req_args, "profile")); hostpath = http_get_hostpath(hc); @@ -677,14 +677,14 @@ http_tag_list_playlist(http_connection_t *hc, int pltype) int idx, count = 0; int chidx, chcount = 0; char *profile, *hostpath; - const char *lang = hc->hc_access->aa_lang_ui; - const char *blank, *sort; + const char *blank, *sort, *lang; idnode_list_mapping_t *ilm; if(hc->hc_access == NULL || access_verify2(hc->hc_access, ACCESS_STREAMING)) return HTTP_STATUS_UNAUTHORIZED; + lang = hc->hc_access->aa_lang_ui; hq = &hc->hc_reply; profile = profile_validate_name(http_arg_get(&hc->hc_req_args, "profile")); hostpath = http_get_hostpath(hc);