Add JSON Schema validation, JSON Pointer and JSON Patch support to jansson_ext - #842
Draft
PengZheng wants to merge 39 commits into
Draft
Add JSON Schema validation, JSON Pointer and JSON Patch support to jansson_ext#842PengZheng wants to merge 39 commits into
PengZheng wants to merge 39 commits into
Conversation
… test coverage, and fix double free.
…management consistency
…proving error handling for circular references
…istency, improve code coverage, and fix a leak.
…lidator and update email format tests
…s and updating related test cases
… and malformed pointers, and update related tests for comprehensive coverage.
…ring buffer functions
… maps for properties and dependencies, improving memory management and performance.
…r null values and self-references, ensuring robust behavior during JSON manipulation.
…and improving error handling during allocation failures, ensuring robust behavior in URI operations.
…e-zeroing requirement, adding automatic cleanup support, and improving memory management in patch operations.
…vided buffers, ensuring proper clearing before use to prevent memory leaks.
…roving buffer reuse, ensuring robust memory management during URI operations.
Close the remaining OOM gaps in celix_jansson_schema.c so that every allocation failure either propagates as an error code or fails the validation closed, instead of crashing, leaking, or silently producing wrong results: - Runtime validators: first-error sinks, the propertyNames key wrapper and the combination error propagation no longer dereference NULL on OOM; path building fail-closes with an out-of-memory error through the shared path_child_checked helper - Compile time: strdup of pattern/format/contentEncoding/required names and json_deep_copy of enum/const now propagate NOMEM instead of storing NULL state that misbehaves at validation time - Registry: celix_stringHashMap_put and retained-vec pushes are checked, so a failed registration returns NOMEM instead of leaking the node and masking itself as a later REF_UNRESOLVED; the document-fragment walk aborts on a failed $id base derivation instead of continuing with a stale base - validate/validate_uri fail with -1 when the patch array cannot be allocated, matching the existing sink-allocation convention - patternProperties regex compilation is checked like the string pattern keyword and reports INVALID_PATTERN Co-Authored-By: Claude <noreply@anthropic.com>
Cover emit_error_v's `ps = ""` fallback, which runs only when celix_jansson_path_str returns NULL after its empty-string strdup fails on OOM. Injecting strdup at path_str (its only strdup call site) makes path_str return NULL and verifies the type error is still reported with an empty path instead of a NULL one. Co-Authored-By: Claude <noreply@anthropic.com>
Second hardening pass over celix_jansson_schema.c: - required/dependencies arrays with a non-string entry no longer crash on strdup(NULL) but are rejected with INVALID_SCHEMA - the not/allOf/anyOf/oneOf logic vec_push failures now release the stolen node and the collected entries and propagate NOMEM, instead of leaking the node and silently dropping the keyword - the default-fill patch path guards a NULL path_str result before snprintf, and celix_json_patch_add failures (OOM) fail the validation closed with an out-of-memory error instead of silently dropping the default patch (both the property and the root-default sites) - json_deep_copy of "default" propagates NOMEM like enum/const instead of silently dropping the default - has_pattern is only set after regcomp succeeds, so a failed regex_t is never regfree'd (undefined behavior per POSIX) Co-Authored-By: Claude <noreply@anthropic.com>
Nine tests covering the new error paths: logic vec_push OOM for not and combo nodes, non-string required/dependencies entries, the default-fill path when path_str returns NULL, default deep_copy OOM for both the type-schema and $ref forms, and patch_add OOM for property and root defaults. celix_json_patch.h is now included for the patch_add caller reference. Coverage stays at 100% for celix_jansson_schema.c. Co-Authored-By: Claude <noreply@anthropic.com>
…nd improve path management with automatic cleanup
- Remove the 'shared' option from the celix recipe: declaring it made Conan treat the celix package as a shared library, which stopped transitive dependencies (mdnsresponder for DNSSD, civetweb headers) from propagating to the test_package consumer. - Bound the openssl override to <4.0.0: fresh dependency resolutions now pick openssl/4.0.1, which civetweb/1.16 cannot compile against. - Expose the celix lib dir via runenv_info in package_info so consumers can find the shared libraries at runtime (previously masked by the shared option). - Drop the now-unneeded jansson requires from the test package. Co-Authored-By: Claude <noreply@anthropic.com>
StrCacheInvalidatedOnPush/Pop compared the pointer to the freed cached string with the new allocation. glibc malloc routinely reuses the just freed address, so the tests failed on non-sanitizer builds (e.g. the coverage workflow) while passing under ASan's quarantine allocator. Assert the rebuilt path content instead, which still catches a stale cache while being deterministic. Co-Authored-By: Claude <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #842 +/- ##
==========================================
+ Coverage 91.62% 92.43% +0.80%
==========================================
Files 235 246 +11
Lines 28787 31849 +3062
==========================================
+ Hits 26377 29439 +3062
Misses 2410 2410 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR lays the foundation of a future JSON Config work, which is a Configuration Admin variant that uses JSON instead of properties. The biggest advantage of using JSON is that we can use JSON Schema as the OSGi Metatype Service for free!
Summary
This PR adds JSON Schema (draft-07) validation, JSON Pointer, and JSON Patch support to the new
jansson_extlibrary, along with the supporting infrastructure needed to make it production-ready.New capabilities
celix_jansson_schema.h): draft-07 keyword support,$refresolution including remote references, recursion depth guard for circular references, abort-on-first-error mode, and a full instance-path reporting mechanism.celix_jansson_pointer.h): parse/evaluate pointers with buffer-reuse and automatic cleanup support.celix_json_patch.h): apply/validate patch documents, with self-reference and null-value guards.celix_jansson_uri):uriformat validation with array-index and malformed-pointer checks, IPv6 zone-id rejection, and automatic cleanup of URI resources.properties/dependencieshandling refactored from hash tables to string hash maps for better memory management.Robustness & hardening
error-injection(EI) tests covering the OOM paths (stdio_eivsnprintf support added).Tests & tooling
celix_util.hwith unit tests for string buffer functions.test_packagesupport forjansson_ext.lcov--ignore-errorsflag removed.rat-excludes.txtupdated for the vendored JSON-Schema-Test-Suite corpus.Files
127 files changed, ~27.4k insertions. The bulk is
libs/jansson_ext/(new library sources, headers, examples, and tests).🤖 Generated with Claude Code