Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
idnode: ensure that idnode_insert return value is checked on all places
  • Loading branch information
perexg committed Aug 20, 2014
1 parent 17319d4 commit 6cbf156
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/access.c
Expand Up @@ -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);

Expand Down
7 changes: 6 additions & 1 deletion src/channels.c
Expand Up @@ -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();
Expand Down
10 changes: 8 additions & 2 deletions src/esfilter.c
Expand Up @@ -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)) {
Expand All @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion src/idnode.c
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion src/input/mpegts/mpegts_input.c
Expand Up @@ -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 */
Expand Down
12 changes: 10 additions & 2 deletions src/input/mpegts/mpegts_mux.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion src/input/mpegts/mpegts_mux_sched.c
Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion src/input/mpegts/mpegts_network.c
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion src/service.c
Expand Up @@ -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);

Expand Down

0 comments on commit 6cbf156

Please sign in to comment.