From aaf97448b0fa67d7eaa701ff20e59cd873e1bf6e Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Thu, 31 Jan 2019 18:30:28 +0000 Subject: [PATCH] Extract EnumListParameter values before checking for matches Previously EnumListParameter would find a match if the parameter starts with any of the values in the enum. This would misfire if an enum value is a prefix of another enum value. Change-Id: I3dc45359afbf7483d9c16a76c0114b5c42daed83 Reviewed-on: https://dart-review.googlesource.com/c/91620 Reviewed-by: Ryan Macnak Commit-Queue: Ryan Macnak --- runtime/vm/service.cc | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/runtime/vm/service.cc b/runtime/vm/service.cc index 4de24424ead..801a02a41af 100644 --- a/runtime/vm/service.cc +++ b/runtime/vm/service.cc @@ -701,27 +701,25 @@ class EnumListParameter : public MethodParameter { return -1; } bool valid_enum = false; + const char* id_start = cp; + while (IsEnumChar(*cp)) { + cp++; + } + if (cp == id_start) { + // Empty identifier, something like this [,]. + return -1; + } + intptr_t id_len = cp - id_start; if (enums_ != NULL) { for (intptr_t i = 0; enums_[i] != NULL; i++) { intptr_t len = strlen(enums_[i]); - if (strncmp(cp, enums_[i], len) == 0) { + if (len == id_len && strncmp(id_start, enums_[i], len) == 0) { element_count++; valid_enum = true; - cp += len; element_allowed = false; // we need a comma first. break; } } - } else { - // Allow any identifiers - const char* id_start = cp; - while (IsEnumChar(*cp)) { - cp++; - } - if (cp == id_start) { - // Empty identifier, something like this [,]. - return -1; - } } if (!valid_enum) { return -1;