Fix NULL dereference crashes in ApiSignature compatibility helpers and add unit tests#293
Conversation
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. |
|
@copilot brakuje jeszcze takiego przypadku w UT, w których byś sprawdzał bardziej rozbudowane wersje, jak np |
… mixed length) Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Dodano 19 nowych testów (łącznie 58) w commicie Wersje dwuczłonowe z kropką (
Wersje wielosegmentowe (
Wersje wielocyfrowe i różnej długości — np. Zgodność działa na poziomie znakowym — porównywany jest tylko pierwszy segment (przed pierwszą |
Dmod_ApiSignature_AreCompatiblecrashed (NULL dereference) whenever signatures lacked a/in the version field (e.g.DMOD_MAKE_SIGNATURE(Mod, 1.0, Func)), had no@(IRQ signatures), or had no:. The three static helpers blindly dereferenced pointers returned bystrchr-based getters without NULL checks.Additionally,
ReadModuleName,ReadVersion, andReadModuleVersionwrote through their output buffer parameter without guarding against NULL.Bug fixes (
src/common/dmod_common.c)NULL-safe compatibility helpers — applied the compact guard pattern in
ApiSignature_AreModulesEqual,ApiSignature_AreApiVersionsCompatible, andApiSignature_AreModuleVersionsCompatible:Semantics: both absent → compatible; one absent → incompatible.
NULL output-buffer guards —
ReadModuleName,ReadVersion, andReadModuleVersionnow returnfalseimmediately when the caller passesNULLas the destination buffer.Unit tests (
tests/system/public/tests_dmod_api_signature.cpp)58 tests covering:
IsValidfor DMOD, BUILTIN, MAL, NULL, and unprefixed stringsAreCompatible— matching pairs, differing name/module/major-API/major-module version, minor-module-version tolerance (1/1.0vs1/1.3), mixed version formats, NULL inputs, DMOD↔BUILTIN cross-type compatibility, and the regression case for the no-/crash (1.0version format)GetName/GetVersion/GetModule/GetModuleVersiongetters and NULL handlingReadModuleName/ReadVersion/ReadModuleVersionincluding NULL buffer and zero-length edge casesIsModuleNameGiven/IsModule/IsMal/IsBuiltinpredicatesA.B/C.D) — e.g.0.3/0.5vs0.7/0.5: same, different API minor (compatible), different API major (incompatible), different module minor (compatible), different module major (incompatible)A.B.C/D.E.F) — e.g.0.3.2/0.67.0vs0.9.1/0.67.0: same, different minor segments (compatible), different majors (incompatible), mixed segment count (0.3.2/0.67.0vs0.3/0.67)10/1vs1/1,0.100/0.200vs0.999/0.888,23.5/0.1vs24.5/0.1,0.3/0.5vs0.300/0.500✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.