mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
Check return value from Dart_PostCObject() in sample extension
Improve the sample code to check Dart_PostCobject(). It prevents possible VM hangs when users sent invalid messages and add error messages. Bug: https://github.com/dart-lang/sdk/issues/35647 Change-Id: Ib0e752c063b0f6c14385de06000f6195c3caf530 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/98743 Commit-Queue: Zichang Guo <zichangguo@google.com> Reviewed-by: Siva Annamalai <asiva@google.com>
This commit is contained in:
parent
47520b1856
commit
7b893ce825
1 changed files with 7 additions and 4 deletions
|
@ -102,7 +102,11 @@ void wrappedRandomArray(Dart_Port dest_port_id,
|
|||
result.value.as_typed_data.type = Dart_TypedData_kUint8;
|
||||
result.value.as_typed_data.values = values;
|
||||
result.value.as_typed_data.length = length;
|
||||
Dart_PostCObject(reply_port_id, &result);
|
||||
if (Dart_PostCObject(reply_port_id, &result)) {
|
||||
Dart_CObject error;
|
||||
error.type = Dart_CObject_kNull;
|
||||
Dart_PostCObject(reply_port_id, &error);
|
||||
}
|
||||
free(values);
|
||||
// It is OK that result is destroyed when function exits.
|
||||
// Dart_PostCObject has copied its data.
|
||||
|
@ -110,9 +114,8 @@ void wrappedRandomArray(Dart_Port dest_port_id,
|
|||
}
|
||||
}
|
||||
}
|
||||
Dart_CObject result;
|
||||
result.type = Dart_CObject_kNull;
|
||||
Dart_PostCObject(reply_port_id, &result);
|
||||
fprintf(stderr, "Invalid message received, cannot proceed. Aborting the process.\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue