From: Jaroslav Kysela Date: Mon, 15 Jan 2018 18:14:30 +0000 (+0100) Subject: next round of coverity fixes X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=745283070d8cc828a94152d07317a470ef01c4a9;p=thirdparty%2Ftvheadend.git next round of coverity fixes --- diff --git a/src/descrambler/cclient.c b/src/descrambler/cclient.c index 17790881d..cd31f8727 100644 --- a/src/descrambler/cclient.c +++ b/src/descrambler/cclient.c @@ -1197,14 +1197,15 @@ cc_conf_changed(caclient_t *cac) caclient_set_status(cac, CACLIENT_STATUS_NONE); return; } + pthread_mutex_lock(&cc->cc_mutex); if (!cc->cc_running) { cc->cc_running = 1; tvh_pipe(O_NONBLOCK, &cc->cc_pipe); snprintf(tname, sizeof(tname), "cc-%s", cc->cc_id); tvhthread_create(&cc->cc_tid, NULL, cc_thread, cc, tname); + pthread_mutex_unlock(&cc->cc_mutex); return; } - pthread_mutex_lock(&cc->cc_mutex); cc->cc_reconfigure = 1; if(cc->cc_fd >= 0) shutdown(cc->cc_fd, SHUT_RDWR); diff --git a/src/epggrab/otamux.c b/src/epggrab/otamux.c index 15716f05a..d705fa9f8 100644 --- a/src/epggrab/otamux.c +++ b/src/epggrab/otamux.c @@ -191,6 +191,11 @@ epggrab_ota_done ( epggrab_ota_mux_t *om, int reason ) epggrab_ota_save(om); mm = mpegts_mux_find0(&om->om_mux_uuid); + if (mm == NULL) { + tvhdebug(LS_EPGGRAB, "unable to find mux %s (grab done: %s)", + uuid_get_hex(&om->om_mux_uuid, name), reasons[reason]); + return; + } tvhdebug(LS_EPGGRAB, "grab done for %s (%s)", mm->mm_nicename, reasons[reason]); mtimer_disarm(&om->om_timer); @@ -660,16 +665,18 @@ epggrab_ota_service_trace ( epggrab_ota_mux_t *ota, { mpegts_mux_t *mm; mpegts_service_t *svc; + const char *nicename; if (!tvhtrace_enabled()) return; mm = mpegts_mux_find0(&ota->om_mux_uuid); + nicename = mm ? mm->mm_nicename : ""; svc = mpegts_service_find_by_uuid0(&svcl->uuid); if (mm && svc) { - tvhtrace(LS_EPGGRAB, "ota %s %s service %s", mm->mm_nicename, op, svc->s_nicename); + tvhtrace(LS_EPGGRAB, "ota %s %s service %s", nicename, op, svc->s_nicename); } else if (tvheadend_is_running()) - tvhtrace(LS_EPGGRAB, "ota %s %s, problem? (%p %p)", mm->mm_nicename, op, mm, svc); + tvhtrace(LS_EPGGRAB, "ota %s %s, problem? (%p %p)", nicename, op, mm, svc); } void diff --git a/src/input/mpegts/dvb_psi_hbbtv.c b/src/input/mpegts/dvb_psi_hbbtv.c index 111576e9b..c9cb2ebb2 100644 --- a/src/input/mpegts/dvb_psi_hbbtv.c +++ b/src/input/mpegts/dvb_psi_hbbtv.c @@ -82,14 +82,14 @@ ts_recv_hbbtv_cb(mpegts_psi_table_t *mt, const uint8_t *buf, int len) switch (dtag) { case DVB_DESC_APP: l3 = *dptr++; dlen--; - if (l3 % 5) goto dvberr; + if (l3 > dlen || (l3 % 5)) goto dvberr; 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; l3 -= 5; } - if (dlen < 3) goto dvberr; + if (dlen < 3 || l3 < 3) goto dvberr; flags = dptr[0]; tvhtrace(mt->mt_subsys, "%s: flags %02X prio %02X", mt->mt_name, dptr[0], dptr[1]); dptr += 2; @@ -101,7 +101,7 @@ ts_recv_hbbtv_cb(mpegts_psi_table_t *mt, const uint8_t *buf, int len) break; case DVB_DESC_APP_NAME: titles = htsmsg_create_list(); - while (dlen > 4) { + while (dlen > 4 && l3 > 4) { r = dvb_get_string_with_len(title, sizeof(title), dptr + 3, dlen - 3, "UTF-8", NULL); if (r < 0) goto dvberr; tvhtrace(mt->mt_subsys, "%s: lang '%c%c%c' name '%s'", mt->mt_name, dptr[0], dptr[1], dptr[2], title); diff --git a/src/profile.c b/src/profile.c index 684f95eb9..d2af4aa51 100644 --- a/src/profile.c +++ b/src/profile.c @@ -936,11 +936,13 @@ profile_sharer_create(profile_sharer_t *prsh, streaming_target_t *dst) { prch->prch_post_share = dst; + pthread_mutex_lock(&prsh->prsh_queue_mutex); prch->prch_ts_delta = LIST_EMPTY(&prsh->prsh_chains) ? 0 : PTS_UNSET; LIST_INSERT_HEAD(&prsh->prsh_chains, prch, prch_sharer_link); prch->prch_sharer = prsh; if (!prsh->prsh_master) prsh->prsh_master = prch; + pthread_mutex_unlock(&prsh->prsh_queue_mutex); return 0; } diff --git a/src/spawn.c b/src/spawn.c index 35fde1055..913132178 100644 --- a/src/spawn.c +++ b/src/spawn.c @@ -639,6 +639,9 @@ spawn_with_passthrough(const char *prog, char *argv[], char *envp[], if(pipe(fd) == -1) { pthread_mutex_unlock(&fork_lock); + // do not pass the local variable outside + if (argv[0] == bin) + argv[0] = NULL; return -1; } @@ -648,6 +651,9 @@ spawn_with_passthrough(const char *prog, char *argv[], char *envp[], pthread_mutex_unlock(&fork_lock); tvherror(LS_SPAWN, "Unable to fork() for \"%s\" -- %s", prog, strerror(errno)); + // do not pass the local variable outside + if (argv[0] == bin) + argv[0] = NULL; return -1; } @@ -737,6 +743,9 @@ spawnv(const char *prog, char *argv[], pid_t *pid, int redir_stdout, int redir_s pthread_mutex_unlock(&fork_lock); tvherror(LS_SPAWN, "Unable to fork() for \"%s\" -- %s", prog, strerror(errno)); + // do not pass the local variable outside + if (argv[0] == bin) + argv[0] = NULL; return -1; }