Skip to content

Fix NULL dereference crashes in ApiSignature compatibility helpers and add unit tests#293

Merged
JohnAmadis merged 3 commits intofeature/fix-compatibility-checkfrom
copilot/sub-pr-292
Mar 11, 2026
Merged

Fix NULL dereference crashes in ApiSignature compatibility helpers and add unit tests#293
JohnAmadis merged 3 commits intofeature/fix-compatibility-checkfrom
copilot/sub-pr-292

Conversation

Copy link
Contributor

Copilot AI commented Mar 11, 2026

Dmod_ApiSignature_AreCompatible crashed (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 by strchr-based getters without NULL checks.

Additionally, ReadModuleName, ReadVersion, and ReadModuleVersion wrote 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, and ApiSignature_AreModuleVersionsCompatible:

    if (moduleVersion1 == NULL || moduleVersion2 == NULL)
    {
        return moduleVersion1 == moduleVersion2;
    }

    Semantics: both absent → compatible; one absent → incompatible.

  • NULL output-buffer guardsReadModuleName, ReadVersion, and ReadModuleVersion now return false immediately when the caller passes NULL as the destination buffer.

Unit tests (tests/system/public/tests_dmod_api_signature.cpp)

58 tests covering:

  • IsValid for DMOD, BUILTIN, MAL, NULL, and unprefixed strings
  • AreCompatible — matching pairs, differing name/module/major-API/major-module version, minor-module-version tolerance (1/1.0 vs 1/1.3), mixed version formats, NULL inputs, DMOD↔BUILTIN cross-type compatibility, and the regression case for the no-/ crash (1.0 version format)
  • GetName / GetVersion / GetModule / GetModuleVersion getters and NULL handling
  • ReadModuleName / ReadVersion / ReadModuleVersion including NULL buffer and zero-length edge cases
  • IsModuleNameGiven / IsModule / IsMal / IsBuiltin predicates
  • Complex / elaborate version strings across three groups:
    • Two-component dotted versions (A.B/C.D) — e.g. 0.3/0.5 vs 0.7/0.5: same, different API minor (compatible), different API major (incompatible), different module minor (compatible), different module major (incompatible)
    • Multi-segment versions (A.B.C/D.E.F) — e.g. 0.3.2/0.67.0 vs 0.9.1/0.67.0: same, different minor segments (compatible), different majors (incompatible), mixed segment count (0.3.2/0.67.0 vs 0.3/0.67)
    • Multi-digit and mixed-length majors — e.g. 10/1 vs 1/1, 0.100/0.200 vs 0.999/0.888, 23.5/0.1 vs 24.5/0.1, 0.3/0.5 vs 0.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.

Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 11, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Copilot AI changed the title [WIP] Fix compatibility check for versions connections Fix NULL dereference crashes in ApiSignature compatibility helpers and add unit tests Mar 11, 2026
@JohnAmadis JohnAmadis marked this pull request as ready for review March 11, 2026 08:24
@JohnAmadis
Copy link
Contributor

@copilot brakuje jeszcze takiego przypadku w UT, w których byś sprawdzał bardziej rozbudowane wersje, jak np 0.3/0.5 lub nawet 0.3.2/0.67.0 - troche poszalej z tymi wersjami, połącz też różne długości itd

… mixed length)

Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 11, 2026

@copilot brakuje jeszcze takiego przypadku w UT, w których byś sprawdzał bardziej rozbudowane wersje, jak np 0.3/0.5 lub nawet 0.3.2/0.67.0 - troche poszalej z tymi wersjami, ...

Dodano 19 nowych testów (łącznie 58) w commicie f7f398e, podzielonych na trzy grupy:

Wersje dwuczłonowe z kropką (A.B/C.D) — np. 0.3/0.5 vs 0.7/0.5:

  • ta sama, inny minor API (zgodne), inny major API (niezgodne), inny minor modułu (zgodne), inny major modułu (niezgodne)

Wersje wielosegmentowe (A.B.C/D.E.F) — np. 0.3.2/0.67.0 vs 0.9.1/0.67.0:

  • ta sama, różne segmenty minor (zgodne), różne majory (niezgodne), mieszana liczba segmentów (0.3.2/0.67.0 vs 0.3/0.67)

Wersje wielocyfrowe i różnej długości — np. 10/1 vs 1/1, 0.100/0.200 vs 0.999/0.888, 23.5 vs 24.5, 0.3 vs 0.300

Zgodność działa na poziomie znakowym — porównywany jest tylko pierwszy segment (przed pierwszą . lub /), więc 0.3 i 0.300 są zgodne, ale 10 i 1 — nie.

@JohnAmadis JohnAmadis merged commit 9f3fcfa into feature/fix-compatibility-check Mar 11, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants