Fixed compatibility check for versions connections#292
Conversation
|
@copilot dopisz unit testy do tej funkcjonalności - takie, które sprawdzą różne sygnatury i czy będą poprawnie podpięte czy nie. Prawdopodobnie te unit testy będą failować, bo z tego co widzę jest jakiś crash, więc wygląda na to, że jakiś błąd zrobiłem - spróbuj go naprawić |
|
@JohnAmadis I've opened a new pull request, #293, to work on those changes. Once the pull request is ready, I'll request review from you. |
There was a problem hiding this comment.
Pull request overview
This PR refactors API signature matching across the DMOD system from strict equality to a compatibility-based comparison, updating call sites and introducing more granular helper checks in the common signature parsing logic.
Changes:
- Replaces
Dmod_ApiSignature_AreEqualwithDmod_ApiSignature_AreCompatibleacross system/public API connection and lookup paths. - Updates signature parsing boundaries for name/module comparisons (using
@for name end and:for module end). - Adds helper functions to separately evaluate API-version and module-version compatibility and uses them in the top-level compatibility check.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/system/public/dmod_dmf_api.c |
Uses compatibility matching when connecting APIs and looking up functions/modules by signature. |
src/system/dmod_system.c |
Updates DIF function lookup to use compatibility matching. |
src/common/dmod_common.c |
Renames/rewires signature comparison to compatibility and adds granular version-compat helpers and delimiter fixes. |
inc/dmod.h |
Exposes the new Dmod_ApiSignature_AreCompatible API. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| static bool ApiSignature_AreModuleVersionsCompatible( const char* Signature1, const char* Signature2 ) | ||
| { | ||
| const char* moduleVersion1 = ApiSignature_GetModuleVersion( Signature1 ); | ||
| const char* moduleVersion2 = ApiSignature_GetModuleVersion( Signature2 ); | ||
|
|
||
| while( *moduleVersion1 != '\0' && *moduleVersion2 != '\0' && *moduleVersion1 != '.' && *moduleVersion2 != '.' ) | ||
| { | ||
| if( *moduleVersion1 != *moduleVersion2 ) | ||
| { | ||
| DMOD_LOG_ERROR("Module version mismatch: %s != %s\n", moduleVersion1, moduleVersion2); | ||
| return false; | ||
| } | ||
| moduleVersion1++; | ||
| moduleVersion2++; | ||
| } | ||
|
|
||
| return *moduleVersion1 == *moduleVersion2; | ||
| } |
There was a problem hiding this comment.
ApiSignature_AreModuleVersionsCompatible() dereferences moduleVersion1/moduleVersion2 without checking for NULL. ApiSignature_GetModuleVersion() returns NULL when the signature version has no '/' (e.g. signatures like "...:1.0" exist in the repo), which will crash when Dmod_ApiSignature_AreCompatible() is used (e.g. from Dmod_GetFunction). Handle missing module-version gracefully (e.g., treat "no module version" as compatible when both are missing, or skip module-version comparison when either side lacks it) before entering the loop.
| @@ -355,7 +357,7 @@ bool Dmod_ApiSignature_AreEqual( const char* Signature1, const char* Signature2 | |||
|
|
|||
There was a problem hiding this comment.
Dmod_ApiSignature_AreCompatible() only checks Dmod_ApiSignature_IsValid(), but IsValid() accepts signature types that don't include '@' / ':' (e.g. IRQ signatures). The helpers called here (ApiSignature_AreModulesEqual(), ApiSignature_AreApiVersionsCompatible()) assume those delimiters exist and can dereference NULL from strchr(), leading to a crash on valid inputs. Consider either tightening IsValid() for the signatures this function supports, or adding delimiter/prefix checks here and returning false (or falling back to strict string compare) when required fields are missing.
| /* | |
| * Some valid signature types (e.g. IRQ signatures) do not contain the | |
| * '@' / ':' delimiters expected by the internal ApiSignature_* helpers. | |
| * Only call those helpers when both signatures have the required | |
| * delimiters; otherwise, fall back to strict string comparison to avoid | |
| * dereferencing NULL pointers from strchr(). | |
| */ | |
| const char* at1 = strchr( Signature1, '@' ); | |
| const char* colon1 = strchr( Signature1, ':' ); | |
| const char* at2 = strchr( Signature2, '@' ); | |
| const char* colon2 = strchr( Signature2, ':' ); | |
| bool hasStructured1 = ( at1 != NULL ) && ( colon1 != NULL ) && ( at1 < colon1 ); | |
| bool hasStructured2 = ( at2 != NULL ) && ( colon2 != NULL ) && ( at2 < colon2 ); | |
| if( !hasStructured1 || !hasStructured2 ) | |
| { | |
| /* For non-structured signatures, treat compatibility as exact match. */ | |
| return strcmp( Signature1, Signature2 ) == 0; | |
| } |
| /** | ||
| * @brief Check if module versions are equal | ||
| * | ||
| * @param Signature1 First signature | ||
| * @param Signature2 Second signature | ||
| * | ||
| * @return true if module versions are compatible, false otherwise | ||
| */ |
There was a problem hiding this comment.
Docstring inconsistency: the @brief says "Check if module versions are equal" but the function name/return description are about compatibility. Update the brief to match the compatibility semantics to avoid misleading generated docs.
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
… mixed length) Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Fix NULL dereference crashes in ApiSignature compatibility helpers and add unit tests
This pull request refactors the API signature comparison logic throughout the codebase to use compatibility checks rather than strict equality. It introduces new helper functions for more granular version compatibility checks and updates all relevant usages and documentation accordingly.
API Signature Compatibility Refactor:
Dmod_ApiSignature_AreEqualwith the newDmod_ApiSignature_AreCompatiblefunction, updating both header (dmod.h) and implementation files to reflect the new compatibility-based approach. [1] [2] [3] [4] [5] [6]Granular Version Compatibility Checks:
ApiSignature_AreApiVersionsCompatible,ApiSignature_AreModuleVersionsCompatible, andApiSignature_AreVersionsCompatibleto separately check API and module version compatibility, and uses these in the main compatibility logic. [1] [2]Documentation and Logging Updates:
Parsing Logic Adjustments:
ApiSignature_AreNamesEqualandApiSignature_AreModulesEqualto properly distinguish between name and module boundaries using@and:respectively. [1] [2]Internal Logic Improvements:
These changes improve the flexibility and correctness of API signature matching, allowing for more robust module interoperation.