]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
a bunch of coverity fixes
authorJaroslav Kysela <perex@perex.cz>
Mon, 15 Jan 2018 14:47:53 +0000 (15:47 +0100)
committerJaroslav Kysela <perex@perex.cz>
Mon, 15 Jan 2018 14:47:53 +0000 (15:47 +0100)
38 files changed:
src/api/api_epg.c
src/descrambler/capmt.c
src/descrambler/descrambler.c
src/descrambler/dvbcam.c
src/descrambler/emm_reass.c
src/dvr/dvr_autorec.c
src/dvr/dvr_db.c
src/dvr/dvr_rec.c
src/epg.c
src/epggrab/module.c
src/htsmsg_binary2.c
src/htsp_server.c
src/input/mpegts/dvb_psi.c
src/input/mpegts/dvb_psi_hbbtv.c
src/input/mpegts/en50221/en50221.c
src/input/mpegts/en50221/en50221_apps.c
src/input/mpegts/en50221/en50221_capmt.c
src/input/mpegts/iptv/iptv.c
src/input/mpegts/iptv/iptv_auto.c
src/input/mpegts/iptv/iptv_http.c
src/input/mpegts/iptv/iptv_libav.c
src/input/mpegts/iptv/iptv_mux.c
src/input/mpegts/linuxdvb/linuxdvb_ca.c
src/input/mpegts/linuxdvb/linuxdvb_frontend.c
src/input/mpegts/linuxdvb/linuxdvb_private.h
src/input/mpegts/linuxdvb/linuxdvb_satconf.c
src/input/mpegts/mpegts_service.c
src/input/mpegts/satip/satip_frontend.c
src/input/mpegts/tsdemux.c
src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c
src/libav.c
src/misc/m3u.c
src/satip/rtsp.c
src/spawn.c
src/transcoding/transcode/context.c
src/uuid.c
src/webui/simpleui.c
src/webui/webui.c

index 30247378c65e0eb363491da07132d402a3d53404..efe62ea15b2857da9299c0fb1caf3f106b4a6b1e 100644 (file)
@@ -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) {
index b9148616e13e841de4e3952d27783b892f23db0b..dcce0d85ed6309b94bc5287dea66d779f878d6f8 100644 (file)
@@ -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);
         }
index 9d1abd91d1099bf7fdcd31427c22a8c5ead92afd..93438cd18dbeb896856b27292b6572cbbc5bbe06 100644 (file)
@@ -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);
index 2b7313ff03945563ccd99a7c19ce194ce193658d..148c2f00d069e89d4dc2f95a8390945fd8684922 100644 (file)
@@ -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);
 }
 
index b6db2e9ba276262f8ef477839ff29c2234698e00..cd730ccb64522209343fb1fcb942473e9f1cd080 100644 (file)
@@ -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)
index 1c79782598f71e4930c752945f84f918b70a8b17..531d6a62e41517c267250a593cfabaf68789e342 100644 (file)
@@ -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;
index cb79609bc77b2d121b0ea708065a5e0bf10375ef..3e8760595a301e7c004847dab44b4c2bb92a103b 100644 (file)
@@ -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 =
index ad05a3678b4ff1271664f7764be762d4e6372752..3de952724b7424400766fb9ee5b42568dfec23db 100644 (file)
@@ -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
index 229476ba275d3e84e11ec88dd8736fc3f6c189df..cf99a37e4378237936d43e693eac8647b4c43a08 100644 (file)
--- 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;
index 9ba1a277c9b23a5ce69ef483eca94edd0ca68ac1..4dceab343401c58b4a383430f3508b4b1ec3af85 100644 (file)
@@ -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);
index 5c5796642e00cb2f0b108a82705def04869e9396..a85aab81ea267a67c386e5456b9b76ae2a183db6 100644 (file)
@@ -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);
index a330e4645c30da98fd2db73782fc5d3ab04615c9..56da562227f8bdf76cf19e96646fbb00bb4db422 100644 (file)
@@ -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)))
index 5fc522fd209d8138ecb1b9e163665b4460e8b7aa..25927b98eb716d5fa90f78a9c6da4299543dc7aa 100644 (file)
@@ -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:
index b13dee7e0f265315a266294750b6e000ac6e6ce3..111576e9bcf47eb3b8e729d85dd43eb252ffcaee 100644 (file)
@@ -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)
index 41a8406cbd352d1f421fdfb9fd6a4f34a799e72c..5697600e1915e3c12dcaf6f236b6460a045ffc9d 100644 (file)
@@ -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,
index ff12d85f6f4bed1c7821a73e31d1ba1b533cdc79..8e8e17b19e5ea711ce342d509e87da3956ec7260 100644 (file)
@@ -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;
           }
         }
       }
index f84702f2a8fb1f2af006b4da67a248ee8b7353ab..e95d4619d685dc4520e75e097871018232ee16d0 100644 (file)
@@ -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);
index 5707a2a22df608b68e94ba456682e9c9ce2ce602..aadd4b806367cdc2053f4538f54fa7731d4f4dfc 100644 (file)
@@ -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);
index 2919d3b4870c65d591b28d81fa14f53d5acfb4ba..11b4a8ffd0921a3b7f4987b393bdd9f756afe62c 100644 (file)
@@ -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)
index cdb188b9b6c5d701b115ad40b480215910de8799..21ae0819df23ea7356d599d3099c42dc059bc6fb 100644 (file)
@@ -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);
index bd14b380eef1b86aae20b9868f85e63d47722d63..35381e89d5c763c3b7c83010921b3aca69402fcd 100644 (file)
@@ -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;
 }
index 3129549f1fa5d58527f4451940209471541540fe..c796a4738c8f5566c14d16098a96f410c19a9cbc 100644 (file)
@@ -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);
 
index d5055ae0065b88df4a1a4e0afbfd7731b29f9187..c70dba3a563d51384d8b6401a6ac60c381fe281d 100644 (file)
@@ -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)) {
index 194dfa2584f72df6e03bbb0a5a92474c53d0953f..0e75259c625c19b54815c22e2e0cf8af5c952b3d 100644 (file)
@@ -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") &&
index 0b6dcd597a47da4cd454bded7fc288e057d56034..3bb239260b782cf7845c686eb005c1729480aa0e 100644 (file)
@@ -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); }
 
index d62b7ab2b22b3e54fd1744f5174e5982db266e3d..9d6ede74ee701c7125a7cc3c64bc8333e9ffcfe7 100644 (file)
@@ -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);
 
index 0a0a90490296ef54e663e1a86c8990da9ed3a5b8..a6946ac9160edee7c779da683f1171303b120d0d 100644 (file)
@@ -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 {
index 0432f004a8abb67ec32652ba7522f667884913a0..43bda829be587c398500732ac3b37dd8699150ee 100644 (file)
@@ -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;
index 32d9ddd7a7a235173950136288235d31e7365607..0ef03d298b019882f43ad59dba64a43d01ef2014 100644 (file)
@@ -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));
index eb2db76dcff0033341e8a5fc938afb77012e0afe..d99be68d1744feca03852ed2826857b01b5279ef 100644 (file)
@@ -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;
 
index bab90a0b464715f12529ac183f52d8edb63db2e9..e87e2cd001fdc2551e8e4cd58019df221380cc7e 100644 (file)
@@ -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])
index 75639da1d7135aef89df9e1269caa2a5b588a555..e86abca794c390704c431a4717a74523ebc010dc 100644 (file)
@@ -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) {
index 631efbbeb3338b9e38f55d8fb2f5aef70c00eeef..7641b85ce49f27ffbf2307ab83871bfcb7a5123d 100644 (file)
@@ -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))
index 13afa12ad4b1a879eacff1a77715b4ec9f54d0cb..35fde105539eddf6aa23fb236b00c1645feaa052 100644 (file)
@@ -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;
 }
 
index 098f05c7a73fac4067d323d4a534ff4606ac8562..f333b32f5036680cdd413f66f58a238d58c97b0f 100644 (file)
@@ -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;
 }
 
index 258948be478569b66ae067ef4fd1a5ab4031d018..75a88773d8df59a1225a9d11fd623e6e5ba406fd 100644 (file)
@@ -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 */
index 8f9107147be6f5c8e3c3ad764c134b97c4f04085..f2cc5fd54be4759ddf31a98a9642913772bf670c 100644 (file)
@@ -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);
index 6bac55e6fc4265ea56ae440a404005092ea06fc0..7cf792df26320445ab0f84c7a39736b4a744f5a1 100644 (file)
@@ -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);