MCPcopy Create free account
hub / github.com/apache/mesos / parseSyscallArgument

Function parseSyscallArgument

src/linux/seccomp/seccomp_parser.cpp:262–319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

260
261
262Try<Nothing> parseSyscallArgument(
263 const JSON::Object& json,
264 ContainerSeccompProfile::Syscall::Arg* arg)
265{
266 auto parseField = [&json](const string& field) -> Try<JSON::Number> {
267 const auto number = json.at<JSON::Number>(field);
268 if (!number.isSome()) {
269 return Error(
270 "Cannot determine '" + field + "' field for 'args' item: " +
271 (number.isError() ? number.error() : "Not found"));
272 }
273
274 return number.get();
275 };
276
277 const auto index = parseField("index");
278 if (index.isError()) {
279 return Error(index.error());
280 }
281
282 arg->set_index(index->as<uint32_t>());
283
284 const auto value = parseField("value");
285 if (value.isError()) {
286 return Error(value.error());
287 }
288
289 arg->set_value(value->as<uint64_t>());
290
291 const auto valueTwo = parseField("valueTwo");
292 if (valueTwo.isError()) {
293 return Error(valueTwo.error());
294 }
295
296 arg->set_value_two(valueTwo->as<uint64_t>());
297
298 const auto op = json.at<JSON::String>("op");
299 if (!op.isSome()) {
300 return Error(
301 "Cannot determine 'op' field for 'args' item: " +
302 (op.isError() ? op.error() : "Not found"));
303 }
304
305 if (!strings::startsWith(op->value, SCMP_PREFIX)) {
306 return Error("Unexpected operation: '" + op->value + "'");
307 }
308
309 ContainerSeccompProfile::Syscall::Arg::Operator opVal;
310
311 if (!ContainerSeccompProfile::Syscall::Arg::Operator_Parse(
312 string(op->value, strlen(SCMP_PREFIX)), &opVal)) {
313 return Error("Unknown operator: '" + op->value + "'");
314 }
315
316 arg->set_op(opVal);
317
318 return Nothing();
319}

Callers 1

foreachFunction · 0.85

Calls 7

startsWithFunction · 0.85
NothingClass · 0.85
errorMethod · 0.65
ErrorFunction · 0.50
isSomeMethod · 0.45
isErrorMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected