-
Notifications
You must be signed in to change notification settings - Fork 0
Fixed compatibility check for versions connections #292
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
Changes from all commits
81323a1
a5f4ea2
ce6cbfa
f7f398e
9f3fcfa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,9 @@ static const char* ApiSignature_GetModuleVersion( const char* Signature ); | |
| static const char* ApiSignature_GetModule( const char* Signature ); | ||
| static bool ApiSignature_AreNamesEqual( const char* Signature1, const char* Signature2 ); | ||
| static bool ApiSignature_AreModulesEqual( const char* Signature1, const char* Signature2 ); | ||
| static bool ApiSignature_AreVersionsEqual( const char* Signature1, const char* Signature2 ); | ||
| static bool ApiSignature_AreApiVersionsCompatible( const char* Signature1, const char* Signature2 ); | ||
| static bool ApiSignature_AreModuleVersionsCompatible( const char* Signature1, const char* Signature2 ); | ||
| static bool ApiSignature_AreVersionsCompatible( const char* Signature1, const char* Signature2 ); | ||
|
|
||
| //============================================================================== | ||
| // FUNCTION IMPLEMENTATIONS | ||
|
|
@@ -228,6 +230,10 @@ bool Dmod_ApiSignature_ReadModuleName( const char* Signature, char* ModuleName, | |
| { | ||
| return false; | ||
| } | ||
| if( ModuleName == NULL ) | ||
| { | ||
| return false; | ||
| } | ||
| if( !Dmod_ApiSignature_IsValid( Signature ) ) | ||
| { | ||
| return false; | ||
|
|
@@ -273,6 +279,10 @@ bool Dmod_ApiSignature_ReadVersion( const char* Signature, char* Version, size_t | |
| { | ||
| return false; | ||
| } | ||
| if( Version == NULL ) | ||
| { | ||
| return false; | ||
| } | ||
| if( !Dmod_ApiSignature_IsValid( Signature ) ) | ||
| { | ||
| return false; | ||
|
|
@@ -313,6 +323,10 @@ bool Dmod_ApiSignature_ReadModuleVersion( const char* Signature, char* ModuleVer | |
| { | ||
| return false; | ||
| } | ||
| if( ModuleVersion == NULL ) | ||
| { | ||
| return false; | ||
| } | ||
| if( !Dmod_ApiSignature_IsValid( Signature ) ) | ||
| { | ||
| return false; | ||
|
|
@@ -339,14 +353,14 @@ bool Dmod_ApiSignature_ReadModuleVersion( const char* Signature, char* ModuleVer | |
| } | ||
|
|
||
| /** | ||
| * @brief Check if API signatures are equal | ||
| * @brief Check if API signatures are compatible | ||
| * | ||
| * @param Signature1 First signature | ||
| * @param Signature2 Second signature | ||
| * | ||
| * @return true if signatures are equal, false otherwise | ||
| * @return true if signatures are compatible, false otherwise | ||
| */ | ||
| bool Dmod_ApiSignature_AreEqual( const char* Signature1, const char* Signature2 ) | ||
| bool Dmod_ApiSignature_AreCompatible( const char* Signature1, const char* Signature2 ) | ||
| { | ||
| if( !Dmod_ApiSignature_IsValid( Signature1 ) || !Dmod_ApiSignature_IsValid( Signature2 ) ) | ||
| { | ||
|
|
@@ -355,7 +369,7 @@ bool Dmod_ApiSignature_AreEqual( const char* Signature1, const char* Signature2 | |
|
|
||
| return ApiSignature_AreNamesEqual( Signature1, Signature2 ) | ||
| && ApiSignature_AreModulesEqual( Signature1, Signature2 ) | ||
| && ApiSignature_AreVersionsEqual( Signature1, Signature2 ); | ||
| && ApiSignature_AreVersionsCompatible( Signature1, Signature2 ); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -472,7 +486,7 @@ static bool ApiSignature_AreNamesEqual( const char* Signature1, const char* Sign | |
| const char* name1 = ApiSignature_GetName( Signature1 ); | ||
| const char* name2 = ApiSignature_GetName( Signature2 ); | ||
|
|
||
| while( *name1 != '\0' && *name2 != '\0' && *name1 != ':' && *name2 != ':' ) | ||
| while( *name1 != '\0' && *name2 != '\0' && *name1 != '@' && *name2 != '@' ) | ||
| { | ||
| if( *name1 != *name2 ) | ||
| { | ||
|
|
@@ -498,7 +512,12 @@ static bool ApiSignature_AreModulesEqual( const char* Signature1, const char* Si | |
| const char* module1 = ApiSignature_GetModule( Signature1 ); | ||
| const char* module2 = ApiSignature_GetModule( Signature2 ); | ||
|
|
||
| while( *module1 != '\0' && *module2 != '\0' && *module1 != '@' && *module2 != '@' ) | ||
| if( module1 == NULL || module2 == NULL ) | ||
| { | ||
| return module1 == module2; | ||
| } | ||
|
|
||
| while( *module1 != '\0' && *module2 != '\0' && *module1 != ':' && *module2 != ':' ) | ||
| { | ||
| if( *module1 != *module2 ) | ||
| { | ||
|
|
@@ -512,23 +531,28 @@ static bool ApiSignature_AreModulesEqual( const char* Signature1, const char* Si | |
| } | ||
|
|
||
| /** | ||
| * @brief Check if versions are equal | ||
| * @brief Check if API versions are compatible | ||
| * | ||
| * @param Signature1 First signature | ||
| * @param Signature2 Second signature | ||
| * | ||
| * @return true if versions are equal, false otherwise | ||
| * @return true if API versions are compatible, false otherwise | ||
| */ | ||
| static bool ApiSignature_AreVersionsEqual( const char* Signature1, const char* Signature2 ) | ||
| static bool ApiSignature_AreApiVersionsCompatible( const char* Signature1, const char* Signature2 ) | ||
| { | ||
| const char* version1 = ApiSignature_GetVersion( Signature1 ); | ||
| const char* version2 = ApiSignature_GetVersion( Signature2 ); | ||
|
|
||
| while( *version1 != '\0' && *version2 != '\0' && *version1 != '.' && *version2 != '.' ) | ||
| if( version1 == NULL || version2 == NULL ) | ||
| { | ||
| return version1 == version2; | ||
| } | ||
|
|
||
| while( *version1 != '\0' && *version2 != '\0' && *version1 != '/' && *version2 != '/' && *version1 != '.' && *version2 != '.' ) | ||
| { | ||
| if( *version1 != *version2 ) | ||
| { | ||
| DMOD_LOG_ERROR("Version mismatch: %s != %s\n", version1, version2); | ||
| DMOD_LOG_ERROR("API version mismatch: %s != %s\n", version1, version2); | ||
| return false; | ||
| } | ||
| version1++; | ||
|
|
@@ -537,3 +561,49 @@ static bool ApiSignature_AreVersionsEqual( const char* Signature1, const char* S | |
|
|
||
| return *version1 == *version2; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Check if module versions are equal | ||
| * | ||
| * @param Signature1 First signature | ||
| * @param Signature2 Second signature | ||
| * | ||
| * @return true if module versions are compatible, false otherwise | ||
| */ | ||
|
Comment on lines
+565
to
+572
|
||
| static bool ApiSignature_AreModuleVersionsCompatible( const char* Signature1, const char* Signature2 ) | ||
| { | ||
| const char* moduleVersion1 = ApiSignature_GetModuleVersion( Signature1 ); | ||
| const char* moduleVersion2 = ApiSignature_GetModuleVersion( Signature2 ); | ||
|
|
||
| if( moduleVersion1 == NULL || moduleVersion2 == NULL ) | ||
| { | ||
| return moduleVersion1 == moduleVersion2; | ||
| } | ||
|
|
||
| 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; | ||
| } | ||
|
Comment on lines
+573
to
+595
|
||
|
|
||
| /** | ||
| * @brief Check if versions are compatible | ||
| * | ||
| * @param Signature1 First signature | ||
| * @param Signature2 Second signature | ||
| * | ||
| * @return true if versions are compatible, false otherwise | ||
| */ | ||
| static bool ApiSignature_AreVersionsCompatible( const char* Signature1, const char* Signature2 ) | ||
| { | ||
| return ApiSignature_AreApiVersionsCompatible( Signature1, Signature2 ) | ||
| && ApiSignature_AreModuleVersionsCompatible( Signature1, Signature2 ); | ||
| } | ||
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.
Dmod_ApiSignature_AreCompatible()only checksDmod_ApiSignature_IsValid(), butIsValid()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 fromstrchr(), leading to a crash on valid inputs. Consider either tighteningIsValid()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.