]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
idnode: ensure that idnode_insert return value is checked on all places
authorJaroslav Kysela <perex@perex.cz>
Wed, 20 Aug 2014 17:27:09 +0000 (19:27 +0200)
committerJaroslav Kysela <perex@perex.cz>
Wed, 20 Aug 2014 17:27:09 +0000 (19:27 +0200)
src/access.c
src/channels.c
src/esfilter.c
src/idnode.c
src/input/mpegts/mpegts_input.c
src/input/mpegts/mpegts_mux.c
src/input/mpegts/mpegts_mux_sched.c
src/input/mpegts/mpegts_network.c
src/service.c

index e99d6d796a384a1df9888716d095982e662381af..0618200d679ca1ad4e0a62df875bb364b760d8dc 100644 (file)
@@ -574,7 +574,12 @@ access_entry_create(const char *uuid, htsmsg_t *conf)
 
   ae = calloc(1, sizeof(access_entry_t));
 
-  idnode_insert(&ae->ae_id, uuid, &access_entry_class, 0);
+  if (idnode_insert(&ae->ae_id, uuid, &access_entry_class, 0)) {
+    if (uuid)
+      tvherror("access", "invalid uuid '%s'", uuid);
+    free(ae);
+    return NULL;
+  }
 
   TAILQ_INIT(&ae->ae_ipmasks);
 
index a72b54c0c41fc5b4ba8bb216ea290b92c4e26a54..3444b5bf8b3106d553b9183b3fbb923ef2e052d7 100644 (file)
@@ -554,7 +554,12 @@ channel_create0
 {
   lock_assert(&global_lock);
 
-  idnode_insert(&ch->ch_id, uuid, idc, IDNODE_SHORT_UUID);
+  if (idnode_insert(&ch->ch_id, uuid, idc, IDNODE_SHORT_UUID)) {
+    if (uuid)
+      tvherror("channel", "invalid uuid '%s'", uuid);
+    free(ch);
+    return NULL;
+  }
   if (RB_INSERT_SORTED(&channels, ch, ch_link, ch_id_cmp)) {
     tvherror("channel", "id collision!");
     abort();
index 3f66ee3c3592560db08da8d98859d280c7775f56..d09e1cae9034c74fa46a9c891bb02c381d64e454 100644 (file)
@@ -144,6 +144,8 @@ esfilter_create
   const idclass_t *c = NULL;
   uint32_t ct;
 
+  lock_assert(&global_lock);
+
   esf->esf_caid = -1;
   esf->esf_caprovider = -1;
   if (ESF_CLASS_IS_VALID(cls)) {
@@ -159,8 +161,12 @@ esfilter_create
     tvherror("esfilter", "wrong class %d!", cls);
     abort();
   }
-  lock_assert(&global_lock);
-  idnode_insert(&esf->esf_id, uuid, c, 0);
+  if (idnode_insert(&esf->esf_id, uuid, c, 0)) {
+    if (uuid)
+      tvherror("esfilter", "invalid uuid '%s'", uuid);
+    free(esf);
+    return NULL;
+  }
   if (conf)
     idnode_load(&esf->esf_id, conf);
   if (ESF_CLASS_IS_VALID(cls))
index 48128a2030a79d9a0df73cbcae1fa86ba898109f..9436e276840ec40bf13b7689d39199e1d6de06ca 100644 (file)
@@ -121,8 +121,10 @@ idnode_insert(idnode_t *in, const char *uuid, const idclass_t *class, int flags)
   in->in_class = class;
   do {
 
-    if (uuid_init_bin(&u, uuid))
+    if (uuid_init_bin(&u, uuid)) {
+      in->in_class = NULL;
       return -1;
+    }
     memcpy(in->in_uuid, u.bin, sizeof(in->in_uuid));
 
     c = NULL;
index f949063f01c150b8767e893e39c53242f75866ad..96b2c176d531740e2329ad81078979a1fdeffd77 100644 (file)
@@ -1043,7 +1043,12 @@ mpegts_input_create0
   ( mpegts_input_t *mi, const idclass_t *class, const char *uuid,
     htsmsg_t *c )
 {
-  idnode_insert(&mi->ti_id, uuid, class, 0);
+  if (idnode_insert(&mi->ti_id, uuid, class, 0)) {
+    if (uuid)
+      tvherror("mpegts", "invalid input uuid '%s'", uuid);
+    free(mi);
+    return NULL;
+  }
   LIST_INSERT_HEAD(&tvh_inputs, (tvh_input_t*)mi, ti_link);
   
   /* Defaults */
index ae8f7bb8fed3a3aea89e3d631726734827b30e7f..0e894435234d3442c720e473a89b5f0c7f2a189b 100644 (file)
@@ -54,8 +54,11 @@ mpegts_mux_instance_create0
   ( mpegts_mux_instance_t *mmi, const idclass_t *class, const char *uuid,
     mpegts_input_t *mi, mpegts_mux_t *mm )
 {
-  idnode_insert(&mmi->mmi_id, uuid, class, 0);
   // TODO: does this need to be an idnode?
+  if (idnode_insert(&mmi->mmi_id, uuid, class, 0)) {
+    free(mmi);
+    return NULL;
+  }
 
   /* Setup links */
   mmi->mmi_mux   = mm;
@@ -884,7 +887,12 @@ mpegts_mux_create0
 {
   char buf[256];
 
-  idnode_insert(&mm->mm_id, uuid, class, 0);
+  if (idnode_insert(&mm->mm_id, uuid, class, 0)) {
+    if (uuid)
+      tvherror("mpegts", "invalid mux uuid '%s'", uuid);
+    free(mm);
+    return NULL;
+  }
 
   /* Enabled by default */
   mm->mm_enabled             = 1;
index 931d357905035551c246853ed483e8f61c64c834..39b3c596d353d55411d469f3ec63de6b5a85d6c5 100644 (file)
@@ -259,7 +259,12 @@ mpegts_mux_sched_create ( const char *uuid, htsmsg_t *conf )
   }
 
   /* Insert node */
-  idnode_insert(&mms->mms_id, uuid, &mpegts_mux_sched_class, 0);
+  if (idnode_insert(&mms->mms_id, uuid, &mpegts_mux_sched_class, 0)) {
+    if (uuid)
+      tvherror("muxsched", "invalid uuid '%s'", uuid);
+    free(mms);
+    return NULL;
+  }
 
   /* Add to list */
   LIST_INSERT_HEAD(&mpegts_mux_sched_all, mms, mms_link);
index b50bf83679545dd98bf912f2e20ca8d91e2f9708..9cbefe1f2c5cb8b610d3e0dffea8d3ac116d295d 100644 (file)
@@ -281,7 +281,12 @@ mpegts_network_create0
   char buf[256];
 
   /* Setup idnode */
-  idnode_insert(&mn->mn_id, uuid, idc, 0);
+  if (idnode_insert(&mn->mn_id, uuid, idc, 0)) {
+    if (uuid)
+      tvherror("mpegts", "invalid network uuid '%s'", uuid);
+    free(mn);
+    return NULL;
+  }
 
   /* Default callbacks */
   mn->mn_display_name   = mpegts_network_display_name;
index a9fdc1f0c58cb942bae7103e27bb73dcc69ca04d..a95df8a8778f9e6474799b3007697cebf15ea6ec 100644 (file)
@@ -831,7 +831,12 @@ service_create0
   ( service_t *t, const idclass_t *class, const char *uuid,
     int source_type, htsmsg_t *conf )
 {
-  idnode_insert(&t->s_id, uuid, class, 0);
+  if (idnode_insert(&t->s_id, uuid, class, 0)) {
+    if (uuid)
+      tvherror("service", "invalid uuid '%s'", uuid);
+    free(t);
+    return NULL;
+  }
 
   lock_assert(&global_lock);