- r = qapi_enum_parse(RunState_lookup, runstate, RUN_STATE__MAX,
- -1, &local_err);
+ if (strnlen((char *)s->runstate,
+ sizeof(s->runstate)) == sizeof(s->runstate)) {
+ /*
+ * This condition should never happen during migration, because
+ * all runstate names are shorter than 100 bytes (the size of
+ * s->runstate). However, a malicious stream could overflow
+ * the qapi_enum_parse() call, so we force the last character
+ * to a NUL byte.
+ */
+ s->runstate[sizeof(s->runstate) - 1] = '\0';
+ }
+ r = qapi_enum_parse(&RunState_lookup, runstate, -1, &local_err);