]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
coverity fixes
authorJaroslav Kysela <perex@perex.cz>
Tue, 27 Oct 2015 09:38:37 +0000 (10:38 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 27 Oct 2015 10:04:50 +0000 (11:04 +0100)
23 files changed:
src/api/api_idnode.c
src/bouquet.c
src/channels.h
src/config.c
src/download.c
src/dvr/dvr_config.c
src/dvr/dvr_rec.c
src/epgdb.c
src/epggrab/channel.c
src/htsp_server.c
src/htsstr.c
src/input/mpegts/dvb_psi.c
src/input/mpegts/dvb_psi_lib.c
src/input/mpegts/linuxdvb/linuxdvb_rotor.c
src/input/mpegts/linuxdvb/linuxdvb_satconf.c
src/lang_codes.c
src/main.c
src/parsers/parser_hevc.c
src/parsers/parsers.c
src/satip/rtp.c
src/satip/server.c
src/tcp.c
src/webui/webui.c

index 122fdf4082f822ef4c95ca508210e35758b25a64..ed3b8d8142df744eb1a6fc19d7beeaf9097c4049 100644 (file)
@@ -408,7 +408,7 @@ api_idnode_save
 
       /* Foreach */
       f = htsmsg_field_find(msg, "uuid");
-      if (!(conf = htsmsg_field_get_list(f)))
+      if (!f || !(conf = htsmsg_field_get_list(f)))
         goto exit;
       HTSMSG_FOREACH(f, conf) {
         if (!(uuid = htsmsg_field_get_str(f)))
index 624d6522a1e8258ca8a453489e6bd11db6d3f6ed..a1ff1f1990a109020c177f27f23b7b637dd8ff39 100644 (file)
@@ -1078,7 +1078,7 @@ service:
           service_t *s = mpegts_service_find_e2(stype, sid, tsid, onid, hash);
           if (s)
             bouquet_add_service(bq, s, ((int64_t)++seen) * CHANNEL_SPLIT, tagname);
-        } else if (lv == 64) {
+        } else if (lv == 0x64) {
           tagname = name;
         }
       }
index 22479a447c683ac4559e3bf718a70b31ff426552..ebb15ec942db250b59fc645d1e9a8dfb38d4cb43 100644 (file)
@@ -164,7 +164,7 @@ void channel_save(channel_t *ch);
 const char *channel_get_name ( channel_t *ch );
 int channel_set_name ( channel_t *ch, const char *name );
 
-#define CHANNEL_SPLIT 1000000
+#define CHANNEL_SPLIT ((int64_t)1000000)
 
 static inline uint32_t channel_get_major ( int64_t chnum ) { return chnum / CHANNEL_SPLIT; }
 static inline uint32_t channel_get_minor ( int64_t chnum ) { return chnum % CHANNEL_SPLIT; }
index d6f20233f0c4a81534786353a748705cf163b4e5..660d1a09a62a1f6eb263b80d7be123eda850dd59 100644 (file)
@@ -1363,6 +1363,7 @@ config_migrate_v23_one ( const char *modname )
   if ((c = hts_settings_load_r(1, "epggrab/%s/channels", modname)) != NULL) {
     HTSMSG_FOREACH(f, c) {
       m = htsmsg_field_get_map(f);
+      if (m == NULL) continue;
       n = htsmsg_copy(m);
       htsmsg_add_str(n, "id", f->hmf_name);
       maj = htsmsg_get_u32_or_default(m, "major", 0);
@@ -1759,13 +1760,15 @@ config_class_cors_origin_set ( void *o, const void *v )
     prop_sbuf[1] = '\0';
   } else {
     urlinit(&u);
-    urlparse(s, &u);
+    if (urlparse(s, &u))
+      goto wrong;
     if (u.scheme && (!strcmp(u.scheme, "http") || !strcmp(u.scheme, "https")) && u.host) {
       if (u.port)
         snprintf(prop_sbuf, PROP_SBUF_LEN, "%s://%s:%d", u.scheme, u.host, u.port);
       else
         snprintf(prop_sbuf, PROP_SBUF_LEN, "%s://%s", u.scheme, u.host);
     } else {
+wrong:
       prop_sbuf[0] = '\0';
     }
     urlreset(&u);
index 12ae3f931fbbd0e2aa80a91ee02f15923d144049..f042f90df6cc51673084bc42280437b48a2f0d01 100644 (file)
@@ -32,7 +32,7 @@ download_file(download_t *dn, const char *filename)
   int fd, res;
   struct stat st;
   char *data, *last_url;
-  size_t r;
+  ssize_t r;
   off_t off;
 
   fd = tvh_open(filename, O_RDONLY, 0);
index 99c13006ba6b2ef0022ff058df717f8c5de38900..1b70d124454499f4bc4ad994d2a771e0c6644cd8 100644 (file)
@@ -123,7 +123,7 @@ dvr_config_find_by_list(htsmsg_t *uuids, const char *name)
       }
     }
   } else {
-    if (cfg->dvr_enabled)
+    if (cfg && cfg->dvr_enabled)
       res = cfg;
   }
   if (!res)
index 8d34c599258e19e35f31f332ef2afb4fbd2df6e3..44f62dc2e89f6cee04b17b55ef8f2743e04ea399 100644 (file)
@@ -112,6 +112,7 @@ dvr_rec_subscribe(dvr_entry_t *de)
                       "(limit %u, dvr limit %u, active DVR %u, streaming %u)",
                aa->aa_username ?: "", aa->aa_representative ?: "",
                aa->aa_conn_limit, aa->aa_conn_limit_dvr, rec_count, net_count);
+      access_destroy(aa);
       return -EOVERFLOW;
     }
   }
@@ -957,7 +958,7 @@ dvr_rec_start(dvr_entry_t *de, const streaming_start_t *ss)
 
     e = htsmsg_create_map();
     htsmsg_add_str(e, "type", streaming_component_type2txt(ssc->ssc_type));
-    if (ssc->ssc_lang && ssc->ssc_lang[0])
+    if (ssc->ssc_lang[0])
        htsmsg_add_str(e, "language", ssc->ssc_lang);
 
     if(SCT_ISAUDIO(ssc->ssc_type)) {
index 3813d1a834a018469b49c4caf1c6bb0b5a823d44..47e19f3c26627441997fcf0f70483fbe50353904 100644 (file)
@@ -172,17 +172,17 @@ void epg_init ( void )
   /* Map file to memory */
   if ( fstat(fd, &st) != 0 ) {
     tvhlog(LOG_ERR, "epgdb", "failed to detect database size");
-    return;
+    goto end;
   }
   if ( !st.st_size ) {
     tvhlog(LOG_DEBUG, "epgdb", "database is empty");
-    return;
+    goto end;
   }
   remain   = st.st_size;
   rp = mem = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
   if ( mem == MAP_FAILED ) {
     tvhlog(LOG_ERR, "epgdb", "failed to mmap database");
-    return;
+    goto end;
   }
 
   /* Process */
@@ -244,6 +244,7 @@ void epg_init ( void )
 
   /* Close file */
   munmap(mem, st.st_size);
+end:
   close(fd);
 }
 
index 804a1174706264e2db6a4c66853b57b01ba280dd..f82876160ccfbb823cc9edfe73bec7d863e152ea 100644 (file)
@@ -62,8 +62,10 @@ epggrab_channel_link_delete
 {
   idnode_list_mapping_t *ilm;
   LIST_FOREACH(ilm, &ec->channels, ilm_in2_link)
-    if (ilm->ilm_in1 == &ec->idnode && ilm->ilm_in2 == &ch->ch_id)
+    if (ilm->ilm_in1 == &ec->idnode && ilm->ilm_in2 == &ch->ch_id) {
       idnode_list_unlink(ilm, NULL);
+      return;
+    }
 }
 
 /* Destroy all links */
@@ -544,7 +546,7 @@ epggrab_channel_class_only_one_notify ( void *obj, const char *lang )
       ilm2 = LIST_NEXT(ilm1, ilm_in2_link);
       ch = (channel_t *)ilm1->ilm_in2;
       if (!first)
-        ch = first;
+        first = ch;
       else if (ch->ch_epgauto && first)
         idnode_list_unlink(ilm1, ec);
     }
index 79af410d89ef9683f145f0c36938648f7a583464..85331efb34e44c1e3b69bc2ca5935dfadfade5b3 100644 (file)
@@ -1755,7 +1755,7 @@ htsp_method_addAutorecEntry(htsp_connection_t *htsp, htsmsg_t *in)
     min_duration = 0;    // 0 = any
   if(htsmsg_get_u32(in, "retention", &retention))
     retention = 0;       // 0 = dvr config
-  if(htsmsg_get_u32(in, "removal", &retention))
+  if(htsmsg_get_u32(in, "removal", &removal))
     removal = 0;         // 0 = dvr config
   if(htsmsg_get_u32(in, "daysOfWeek", &days_of_week))
     days_of_week = 0x7f; // all days
index 71e33c9b554a32b018f19508e96cf20b1150373a..e435d38f3852356f05f698766ec5b0bed21158b4 100644 (file)
@@ -237,8 +237,9 @@ htsstr_substitute(const char *src, char *dst, size_t dstlen,
       if (dstlen < 2)
         break;
       *dst = '\\'; src++; dst++; dstlen--;
-      if (*src)
+      if (*src) {
         *dst = *src; src++; dst++; dstlen--;
+      }
       continue;
     }
     if (first >= 0) {
index 7d5384c2e7642d64d56e58cb1b88736737c7caf0..43d42f975fd0a7abb47db01d80fadc22fd562408 100644 (file)
@@ -2431,8 +2431,10 @@ static void dvb_time_update(const uint8_t *ptr, const char *srcname)
   time_t t;
   if (dvb_last_update + 1800 < dispatch_clock) {
     t = dvb_convert_date(ptr, 0);
-    tvhtime_update(t, srcname);
-    dvb_last_update = dispatch_clock;
+    if (t > 0) {
+      tvhtime_update(t, srcname);
+      dvb_last_update = dispatch_clock;
+    }
   }
 }
 
index c7f47b6ccd2cd55f0205c495390bfceebac1cb54..c8a96d138abb2d25406af43509f48d8e2480b071 100644 (file)
@@ -469,6 +469,10 @@ int dvb_table_remux
     buf += l;
   }
 
+  if (ol <= 0) {
+    free(obuf);
+    return 0;
+  }
   *out = obuf;
   return ol;
 }
index be4fe06d91496eabc5a6ee7b02d8194fc8268eb9..ec9b9c598ef8373f20bbbd86e79c07bf7ad6db19 100644 (file)
@@ -498,12 +498,12 @@ linuxdvb_rotor_create0
         ld->ld_tune  = linuxdvb_rotor_tune;
         ld->ld_grace = linuxdvb_rotor_grace;
         ld->ld_post  = linuxdvb_rotor_post;
+        lr = (linuxdvb_rotor_t *)ld;
+        if (lr->lr_powerup_time == 0)
+          lr->lr_powerup_time = 100;
+        if (lr->lr_cmd_time == 0)
+          lr->lr_cmd_time = 25;
       }
-      lr = (linuxdvb_rotor_t *)ld;
-      if (lr->lr_powerup_time == 0)
-        lr->lr_powerup_time = 100;
-      if (lr->lr_cmd_time == 0)
-        lr->lr_cmd_time = 25;
     }
   }
                                  
index cd457d45e6f6559823b8d13a8e8f3ce3f66ebdc8..3bf49f86a3d7fc4ac35e9132d4c5706f9d248295 100644 (file)
@@ -858,8 +858,7 @@ int
 linuxdvb_satconf_start_mux
   ( linuxdvb_satconf_t *ls, mpegts_mux_instance_t *mmi, int skip_diseqc )
 {
-  int r;
-  uint32_t f;
+  int r, f;
   linuxdvb_satconf_ele_t *lse = linuxdvb_satconf_find_ele(ls, mmi->mmi_mux);
   linuxdvb_frontend_t    *lfe = (linuxdvb_frontend_t*)ls->ls_frontend;
 
index bc31ba0ceca7d03367f7019f23feb85a5ece2a4d..bb44efb749e6c751b56fc39725cb668df8befad2 100644 (file)
@@ -704,14 +704,14 @@ char *lang_code_user( const char *ucode )
   if (!codes)
     return ucode ? strdup(ucode) : NULL;
   if (!ucode)
-    return codes ? strdup(codes) : NULL;
-  ret = malloc(strlen(codes) + strlen(ucode ?: "") + 2);
+    return strdup(codes);
+  ret = malloc(strlen(codes) + strlen(ucode) + 2);
   strcpy(ret, ucode);
   while (codes && *codes) {
     s = codes;
     while (*s && *s != ',')
       s++;
-    if (strncmp(codes, ucode ?: "", s - codes)) {
+    if (strncmp(codes, ucode, s - codes)) {
       strcat(ret, ",");
       strncat(ret, codes, s - codes);
     }
index 81c7f7bc7627d1cd02423777024af664905215ed..06fd2381e66f42aa09eee6b6ba4ef7c663dd412e 100644 (file)
@@ -765,9 +765,11 @@ main(int argc, char **argv)
     /* Find option */
     cmdline_opt_t *opt
       = cmdline_opt_find(cmdline_opts, ARRAY_SIZE(cmdline_opts), argv[i]);
-    if (!opt)
+    if (!opt) {
       show_usage(argv[0], cmdline_opts, ARRAY_SIZE(cmdline_opts),
                  _("invalid option specified [%s]"), argv[i]);
+      continue;
+    }
 
     /* Process */
     if (opt->type == OPT_BOOL)
index 1063ba69ad469ad2658ced73a7baf52522c71286..145e533025e61b4b1219cfed1c60ffb6730ff8b5 100644 (file)
@@ -1257,14 +1257,14 @@ static const uint8_t vui_sar[][2] = {
   {  2,   1 },
 };
 
-static uint32_t ilog2(uint32_t v)
+static uint_fast32_t ilog2(uint32_t v)
 {
-  uint32_t r;
+  uint_fast32_t r = 0;
   while (v) {
     v >>= 1;
     r++;
   }
-  return v;
+  return r;
 }
 
 static inline int check_width(uint32_t w)
@@ -1494,7 +1494,7 @@ hevc_decode_sps(elementary_stream_t *st, bitstream_t *bs)
   if (log2_min_tb_size >= log2_min_cb_size || log2_min_tb_size < 2)
     return;
   log2_diff_max_min_transform_block_size = read_golomb_ue(bs);
-  if (log2_diff_max_min_transform_block_size < 0 || log2_diff_max_min_transform_block_size > 30)
+  if (log2_diff_max_min_transform_block_size > 30)
     return;
 
   read_golomb_ue(bs); /* max_transform_hierarchy_depth_inter */
@@ -1557,7 +1557,7 @@ hevc_decode_sps(elementary_stream_t *st, bitstream_t *bs)
     u = read_golomb_ue(bs); /* num_long_term_ref_pics_sps */
     if (u > 31)
       return;
-    for (i = 0; i < u; u++) {
+    for (i = 0; i < u; i++) {
       skip_bits(bs, log2_max_poc_lsb);
       skip_bits1(bs);
     }
@@ -1579,6 +1579,8 @@ hevc_decode_sps(elementary_stream_t *st, bitstream_t *bs)
 
   log2_ctb_size = log2_min_cb_size +
                   log2_diff_max_min_coding_block_size;
+  if (log2_ctb_size > 18)
+    return;
 
   sps->ctb_width  = (width  + (1 << log2_ctb_size) - 1) >> log2_ctb_size;
   sps->ctb_height = (height + (1 << log2_ctb_size) - 1) >> log2_ctb_size;
index b887e33c98e79e903d863c45fff07ce71603486b..4451b9edef2856a0b4a86b7c935317904fcf6f90 100644 (file)
@@ -350,7 +350,7 @@ parse_pes(service_t *t, elementary_stream_t *st, const uint8_t *data, int len,
       if(j < hlen + 5)
         break;
       
-      r = parse_pes_header(t, st, st->es_buf.sb_data + off + 2, hlen + 3);
+      parse_pes_header(t, st, st->es_buf.sb_data + off + 2, hlen + 3);
 
       st->es_header_mode = 0;
       st->es_buf.sb_ptr = off;
index 5bebac35d62c91717a5e3bab8130d284f0a87731..97274ec26a8bb496a265da4e288eb6dd2a56b2a7 100644 (file)
@@ -429,12 +429,15 @@ void satip_rtp_update_pmt_pids(void *id, mpegts_apids_t *pmt_pids)
         tbl = calloc(1, sizeof(*tbl));
         dvb_table_parse_init(&tbl->tbl, "satip-pmt", pid, rtp);
         tbl->pid = pid;
+        TAILQ_INSERT_TAIL(&rtp->pmt_tables, tbl, link);
       }
     }
     for (tbl = TAILQ_FIRST(&rtp->pmt_tables); tbl; tbl = tbl_next){
       tbl_next = TAILQ_NEXT(tbl, link);
-      if (tbl->remove_mark)
+      if (tbl->remove_mark) {
         TAILQ_REMOVE(&rtp->pmt_tables, tbl, link);
+        free(tbl);
+      }
     }
     pthread_mutex_unlock(&rtp->lock);
   }
@@ -463,6 +466,7 @@ void satip_rtp_close(void *id)
     while ((tbl = TAILQ_FIRST(&rtp->pmt_tables)) != NULL) {
       dvb_table_parse_done(&tbl->tbl);
       TAILQ_REMOVE(&rtp->pmt_tables, tbl, link);
+      free(tbl);
     }
     pthread_mutex_destroy(&rtp->lock);
     free(rtp);
index 2d91e0ac4f7c28b21a2665ac73ac745f76598d1c..3ba8a71df04b10867fb43bafb4c7539d2b339a7a 100644 (file)
@@ -296,7 +296,7 @@ DEVICEID.SES.COM: %d\r\n\r\n"
 
   tvhtrace("satips", "sending announce");
 
-  for (attempt = 1; attempt < 3; attempt++) {
+  for (attempt = 1; attempt <= 3; attempt++) {
     switch (attempt) {
     case 1:
       nt = "upnp:rootdevice";
index 9d65a35c7abfd1a4a490c5ed4c0e6530e6b1800b..03a1a5efab5252562d6b1aa4535c169ceca9d099 100644 (file)
--- a/src/tcp.c
+++ b/src/tcp.c
@@ -91,7 +91,7 @@ tcp_connect(const char *hostname, int port, const char *bindaddr,
   }
 
   fd = tvh_socket(ai->ai_family, SOCK_STREAM, 0);
-  if(fd == -1) {
+  if(fd < 0) {
     snprintf(errbuf, errbufsize, "Unable to create socket: %s",
             strerror(errno));
     freeaddrinfo(ai);
@@ -114,6 +114,7 @@ tcp_connect(const char *hostname, int port, const char *bindaddr,
                                      ai->ai_family == AF_INET6 ? "6" : "4",
                                      bindaddr);
         freeaddrinfo(ai);
+        close(fd);
         return -1;
       }
     }
@@ -126,7 +127,7 @@ tcp_connect(const char *hostname, int port, const char *bindaddr,
   r = connect(fd, ai->ai_addr, ai->ai_addrlen);
   freeaddrinfo(ai);
 
-  if(r == -1) {
+  if(r < 0) {
     /* timeout < 0 - do not wait at all */
     if(errno == EINPROGRESS && timeout < 0) {
       err = 0;
index c0fd5826d35e6ae2e51aa6f4a98b401d2bf23a15..f04250b776c1cd3a593fce9e1b379a8cbb2a3664 100644 (file)
@@ -837,7 +837,7 @@ http_dvr_list_playlist(http_connection_t *hc, int pltype)
   char buf[255];
   dvr_entry_t *de;
   const char *uuid;
-  char *hostpath = http_get_hostpath(hc);
+  char *hostpath;
   off_t fsize;
   time_t durration;
   struct tm tm;
@@ -847,6 +847,7 @@ http_dvr_list_playlist(http_connection_t *hc, int pltype)
     return HTTP_STATUS_BAD_REQUEST;
 
   hq = &hc->hc_reply;
+  hostpath = http_get_hostpath(hc);
 
   htsbuf_qprintf(hq, "#EXTM3U\n");
   LIST_FOREACH(de, &dvrentries, de_global_link) {
@@ -1056,11 +1057,11 @@ http_stream_service(http_connection_t *hc, service_t *service, int weight)
     return HTTP_STATUS_UNAUTHORIZED;
 
   if ((str = http_arg_get(&hc->hc_req_args, "descramble")))
-    if (strcmp(str ?: "", "0") == 0)
+    if (strcmp(str, "0") == 0)
       eflags |= SUBSCRIPTION_NODESCR;
 
   if ((str = http_arg_get(&hc->hc_req_args, "emm")))
-    if (strcmp(str ?: "", "1") == 0)
+    if (strcmp(str, "1") == 0)
       eflags |= SUBSCRIPTION_EMM;
 
   flags = SUBSCRIPTION_MPEGTS | eflags;
@@ -1517,6 +1518,8 @@ page_dvrfile(http_connection_t *hc, const char *remain, void *opaque)
     basename++; /* Skip '/' */
     str0 = intlconv_utf8safestr(intlconv_charset_id("ASCII", 1, 1),
                                 basename, strlen(basename) * 3);
+    if (str0 == NULL)
+      return HTTP_STATUS_INTERNAL;
     htsbuf_queue_init(&q, 0);
     htsbuf_append_and_escape_url(&q, basename);
     str = htsbuf_to_string(&q);