]> git.alsa-project.org Git - alsa-utils.git/commitdiff
topology: fix potential null pointer from strchr
authorChao Song <chao.song@linux.intel.com>
Mon, 31 May 2021 02:29:57 +0000 (10:29 +0800)
committerJaroslav Kysela <perex@perex.cz>
Wed, 2 Jun 2021 14:55:57 +0000 (16:55 +0200)
This patch adds check to the return pointer from strchr,
because it may be null and cause segment fault, if component
is not properly constructed.

Fixes: https://github.com/alsa-project/alsa-utils/pull/91
Signed-off-by: Chao Song <chao.song@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
topology/pre-process-dapm.c
topology/pre-process-object.c

index 450ca7173dce6fe4d5fe9d2173fdcebf7fe2fde8..dbaf2f113f0b1dc1a5f25290900a145219b0e1f0 100644 (file)
@@ -146,6 +146,11 @@ static int tplg_pp_get_widget_name(struct tplg_pre_processor *tplg_pp,
 
        /* get class name */
        args = strchr(string, '.');
+       if (!args) {
+               SNDERR("Error getting class name for %s\n", string);
+               return -EINVAL;
+       }
+
        class_name = calloc(1, strlen(string) - strlen(args) + 1);
        if (!class_name)
                return -ENOMEM;
index 09aa3758520a10454aeaa24ab64d130afce2cd93..ac8caeca425e6e1f676624ae3d95f8a94a95bc65 100644 (file)
@@ -492,6 +492,11 @@ static int tplg_pp_add_object_tuple_section(struct tplg_pre_processor *tplg_pp,
        }
 
        type = strchr(token_ref, '.');
+       if(!type) {
+               SNDERR("Error getting type for %s\n", token_ref);
+               return -EINVAL;
+       }
+
        token = calloc(1, strlen(token_ref) - strlen(type) + 1);
        if (!token)
                return -ENOMEM;