ucm: Use strncmp to avoid access-out-of-boundary

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>
This commit is contained in:
paulhsia 2019-11-30 03:35:30 +08:00 committed by Jaroslav Kysela
parent 1c7e46d5d8
commit c79f09e1f5

View file

@ -61,11 +61,13 @@ static int check_identifier(const char *identifier, const char *prefix)
{ {
int len; int len;
if (strcmp(identifier, prefix) == 0)
return 1;
len = strlen(prefix); 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 1;
return 0; return 0;
} }