-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/dfi cleanup #699
Feature/dfi cleanup #699
Conversation
`tc.cache_variables["CMAKE_EXE_LINKER_FLAGS"] = "-Wl,--unresolved-symbols=ignore-in-shared-libs"` would be overriden previously.
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #699 +/- ##
==========================================
+ Coverage 88.50% 88.90% +0.40%
==========================================
Files 212 216 +4
Lines 24606 24293 -313
==========================================
- Hits 21777 21598 -179
+ Misses 2829 2695 -134 ☔ View full report in Codecov by Sentry. |
Also remove dync_common from public interface of dfi.
…improve interface ergonomic to dyn_interface.
…s that cannot fail.
# Conflicts: # bundles/pubsub/pubsub_serializer_json/src/pubsub_json_serialization_provider.c # bundles/pubsub/pubsub_utils/gtest/src/PubSubMatchingTestSuite.cpp # bundles/pubsub/pubsub_utils/gtest/src/PubSubSerializationHandlerTestSuite.cc # bundles/pubsub/pubsub_utils/src/pubsub_serialization_provider.c
…n_descriptor and improve ergonomics of dyn_message API.
…ve tail recursion from dynType_findType.
# Conflicts: # libs/error_injector/stdio/CMakeLists.txt # libs/error_injector/stdio/include/stdio_ei.h # libs/error_injector/stdio/src/stdio_ei.cc
…or of missing the closing brace.
…ustness and coverage.
1. The first method argument must be of handle type. 2. Only one output argument (either am=pre or am=out) is allowed. 3. Output argument (if any) must be the last argument.
1. Apply early return to make error handling dead simple. 2. Remove unnecessary argument list iterations. 3. Protect against user-provided nullptr. 4. Deal with invalid text output.
…e jsonRpc_prepareInvokeRequest. 1. Remove unnecessary argument list iteration by removing usages of dynFunction_argumentTypeForIndex and dynFunction_argumentMetaForIndex. 2. Add more tests using error injection.
1. Add support for nullptr result for `am=out` parameter. 2. Fix memory leaks when `am=out` result fails to serialize. 3. Extract dynInterface_findMethod.
For any method, there must be exactly one handle argument, that is, the first one.
1. Limit max number of arguments to CELIX_JSON_RPC_MAX_ARGS. 2. Apply early return error handling. 3. Simplify arguments manipulation and check for argument number mismatch. 4. More error injection tests.
`rpcArgs` refers to stack variables, which must be declared before `rpcArgs`.
I will try to find to time to review this PR, this week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still reviewing.
Nice to see that libdfi gets some attention and refactoring :)
I really enjoy seeing te early returns and usage of celix_err.
It has been a while since I looked into this code, so reviewing will take some days.
I do remember that I really liked creating libdfi; It is quite a powerful concept, complex to implement and wrap your head around (ffi with a pointer to a argument array, where the argument entries are pointers to the argument values and the argument values can be pointers or even a double output pointers) , but it possible to nice split up the parsing and usage in small functions.
Originally my idea was also to allow optional usage of libdfi in the framework so that it would be possible to (e.g.) use a service struct of version 1.0.0 while the provided service is 1.1.0. With libdfi is should be possible to ad-hoc create a 1.0.0 version based on the 1.0.0 and 1.1.0 descriptor (assuming correct usage of semver). But I digress.
if (!dynType_isTrivial(entry->type)) { | ||
type->trivial = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!dynType_isTrivial(entry->type)) { | |
type->trivial = false; | |
type->trivial = dynType_isTrivial(entry->type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intention here is if ANY of its field is non-trivial, then the complex itself is non-trivial, otherwise it is trivial (as set in line 247).
But with the suggested modification, the triviality of a complex is determined by its last field.
Co-authored-by: Pepijn Noltes <pnoltes@apache.org>
Thanks for sharing the background with me. I pretended to be cool, but let me admit it: the libdfi work is eyeopening, which leads to another "WOW, things could really be done like this" awe. Inspired by the Rust POC, to be more concrete, the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Nice and needed refactoring libdfi.
Introduction
This PR is a preliminary work of #590. The main motivation behind this is to familiarize myself of the underlying mechanism of RSA, i.e. libdfi. Reading the code base alone is not enough, it should also be thoroughly tested and debugged. That way not only did I get a full understanding, I also found and fixed several ambiguities and bugs along the way.
Hopefully, after this PR merged, libdfi is robust enough to handle most (if not all) of malformed descriptors and all malicious JSON requests/responses.
Precise Definitions of DFI Argument Types
Previously, we don't have such "formal" definitions. As mentioned by #723, it is fairly easy to construct "legal" interface descriptor to introduce use-after-free bugs. To address this, we introduce the notion of trivial type and perform strict checking in
dynFunction_parse
. Note that "serializability" check is left for the jsonSerializer to perform.RSA Interface Convention Enforcement
am=handle
can appear exactly once.am=pre
oram=out
) is only allowed as the last one. Therefore, there is at most one output parameter.We enforce the convention in
dynInterface_checkInterface
so that arguments handling in json_rpc.c can be greatly simplified.Please consider adding the above two into #690. @xuzhenbao
Early Return Error Handling Pattern
Previously, error handling is done using chained status check:
With chained status check, it is relative easy to achieve high line coverage.
However, the branch coverage is still low and the control flow is often difficult to follow.
By applying early return uniformly in libdfi, by archiving high line coverage, we are almost guaranteed high branch coverage and the readability is often improved.
Remove AVRO
It is currently incomplete and unused, so is removed by this PR.
After completing #590, we can reconsider introducing more efficient serialization mechanism (including AVRO).
Other Enhancements and Improvements
nullptr
for pointer type.celix_auto
is used extensively. Please note that a caveat related to stack variable declaration order is highlighted in this commit: 876471d The interesting thing is that this issue only manifests itself in clang builds.const
qualifier is applied where appropriate.dynType_realType
to deal with reference type and fix several related crashes.