Skip to content

Commit f90706d

Browse files
robertwoj-microsoftcopilot
andauthored
assessor: handle escaped quotes in MOF GetValue (#1276)
The MOF format escapes inner double quotes as " inside quoted string values. The previous GetValue() implementation searched for the next '"' literally, which truncated values like: DesiredObjectValue = "{"mountPoint":"/tmp"}"; to just '{\' before the JSON parser ever saw them. The compliance engine then fell back to a key=value parser, which rejected '{' as a key character and emitted "Invalid key: only alphanumeric and underscore characters are allowed" once per rule with structured parameters. Walk the string instead, honouring " and \ escape sequences, so a JSON-encoded DesiredObjectValue arrives at UpdateUserParameters() in its original unescaped form. Co-authored-by: copilot <copilot@local>
1 parent ef858b0 commit f90706d

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

  • src/modules/complianceengine/src/assessor

src/modules/complianceengine/src/assessor/Mof.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,32 @@ string GetValue(const std::string& line)
2020
{
2121
return std::string();
2222
}
23-
const auto end = line.find('"', start + 1);
24-
if (end == std::string::npos)
23+
// Walk from the opening quote, honouring \" and \\ escape sequences so
24+
// that MOF string values like "{\"key\":\"val\"}" are returned
25+
// unescaped as {"key":"val"} instead of being truncated at the first
26+
// inner quote.
27+
std::string result;
28+
size_t pos = start + 1;
29+
while (pos < line.size())
2530
{
26-
return std::string();
31+
if (line[pos] == '\\' && pos + 1 < line.size())
32+
{
33+
const char next = line[pos + 1];
34+
if (next == '"' || next == '\\')
35+
{
36+
result += next;
37+
pos += 2;
38+
continue;
39+
}
40+
}
41+
else if (line[pos] == '"')
42+
{
43+
break;
44+
}
45+
result += line[pos];
46+
++pos;
2747
}
28-
return line.substr(start + 1, end - (start + 1));
48+
return result;
2949
};
3050
} // anonymous namespace
3151

0 commit comments

Comments
 (0)