edje_cc: fix segfault when a program attempts to play a non-registered sound
authorJean Guyomarc'h <jean.guyomarch@gmail.com>
Mon, 12 Oct 2015 19:04:38 +0000 (12:04 -0700)
committerCedric BAIL <cedric@osg.samsung.com>
Mon, 12 Oct 2015 21:01:23 +0000 (14:01 -0700)
Summary:
When an edje program attempted to play a sound that was not registered
(e.g. in a sounds{} block), edje_cc would segfault instead of throwing
an error.

@fix

Reviewers: cedric

Reviewed By: cedric

Subscribers: cedric

Differential Revision: https://phab.enlightenment.org/D3171

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
src/bin/edje/edje_cc_handlers.c

index c214f5b..b96647a 100644 (file)
@@ -12781,6 +12781,7 @@ st_collections_group_programs_program_action(void)
    Edje_Part_Collection *pc;
    Edje_Program *ep;
    int i;
+   Eina_Bool found = EINA_FALSE;
 
    pc = eina_list_data_get(eina_list_last(edje_collections));
    if (sequencing)
@@ -12828,16 +12829,22 @@ st_collections_group_programs_program_action(void)
    else if (ep->action == EDJE_ACTION_TYPE_SOUND_SAMPLE)
      {
         ep->sample_name = parse_str(1);
-        for (i = 0; i < (int)edje_file->sound_dir->samples_count; i++)
+        if (edje_file->sound_dir)
           {
-             if (!strcmp(edje_file->sound_dir->samples[i].name, ep->sample_name))
-               break;
-             if (i == (int)(edje_file->sound_dir->samples_count - 1))
+             for (i = 0; i < (int)edje_file->sound_dir->samples_count; i++)
                {
-                  ERR("No Sample name %s exist.", ep->sample_name);
-                  exit(-1);
+                  if (!strcmp(edje_file->sound_dir->samples[i].name, ep->sample_name))
+                    {
+                       found = EINA_TRUE;
+                       break;
+                    }
                }
           }
+        if (!found)
+          {
+             ERR("No Sample name %s exist.", ep->sample_name);
+             exit(-1);
+          }
         ep->speed = parse_float_range(2, 0.0, 100.0);
         if (get_arg_count() >= 4)
           ep->channel = parse_enum(3,
@@ -12853,16 +12860,22 @@ st_collections_group_programs_program_action(void)
    else if (ep->action == EDJE_ACTION_TYPE_SOUND_TONE)
      {
         ep->tone_name = parse_str(1);
-        for (i = 0; i < (int)edje_file->sound_dir->tones_count; i++)
+        if (edje_file->sound_dir)
           {
-             if (!strcmp(edje_file->sound_dir->tones[i].name, ep->tone_name))
-               break;
-             if (i == (int)(edje_file->sound_dir->tones_count - 1))
+             for (i = 0; i < (int)edje_file->sound_dir->tones_count; i++)
                {
-                  ERR("No Tone name %s exist.", ep->tone_name);
-                  exit(-1);
+                  if (!strcmp(edje_file->sound_dir->tones[i].name, ep->tone_name))
+                    {
+                       found = EINA_TRUE;
+                       break;
+                    }
                }
           }
+        if (!found)
+          {
+             ERR("No Tone name %s exist.", ep->tone_name);
+             exit(-1);
+          }
         ep->duration = parse_float_range(2, 0.1, 10.0);
      }
    else if (ep->action == EDJE_ACTION_TYPE_VIBRATION_SAMPLE)