]> git.alsa-project.org Git - alsa-lib.git/commitdiff
ucm: Use strncmp to avoid access-out-of-boundary
authorpaulhsia <paulhsia@chromium.org>
Fri, 29 Nov 2019 19:35:30 +0000 (03:35 +0800)
committerJaroslav Kysela <perex@perex.cz>
Fri, 29 Nov 2019 19:48:56 +0000 (20:48 +0100)
If the length of the identifier is less than the length of the prefix,
access-out-of-boundary will occur in memcmp().

Signed-off-by: paulhsia <paulhsia@chromium.org>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
src/ucm/main.c

index b0b6ffb34be5c3ef643c49c7c42c84cdc0ea1c7f..252e50d9a38701eee030c0da84e4398e374d4f66 100644 (file)
@@ -61,11 +61,13 @@ static int check_identifier(const char *identifier, const char *prefix)
 {
        int len;
 
-       if (strcmp(identifier, prefix) == 0)
-               return 1;
        len = strlen(prefix);
-       if (memcmp(identifier, prefix, len) == 0 && identifier[len] == '/')
+       if (strncmp(identifier, prefix, len) != 0)
+               return 0;
+
+       if (identifier[len] == 0 || identifier[len] == '/')
                return 1;
+
        return 0;
 }