Skip to content

detect: fail thread init on keyword ctx error (and fix cbindgen build break) - #15589

Closed
ssam18 wants to merge 2 commits into
OISF:mainfrom
ssam18:filemagic-threadinit-fail-8237-v2
Closed

detect: fail thread init on keyword ctx error (and fix cbindgen build break)#15589
ssam18 wants to merge 2 commits into
OISF:mainfrom
ssam18:filemagic-threadinit-fail-8237-v2

Conversation

@ssam18

@ssam18 ssam18 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Contribution style:

Our Contribution agreements:

Changes (if applicable):

Link to ticket: https://redmine.openinfosecfoundation.org/issues/8237

Describe changes:

  • Supersedes detect: fail thread init on keyword ctx error #15588. This version also fixes the unrelated build break that was failing CI there.
  • Commit 1 (build fix): detect: guard duplicate bytemath endian macro. Newer cbindgen (>= 0.29.3, e.g. 0.29.4) now exports the long-standing Rust pub const DETECT_BYTEMATH_ENDIAN_DEFAULT into rust-bindings.h as a macro. That collides under -Werror with the macro defined under UNITTESTS in detect-bytemath.c, which is why every build job on main started failing. The C macro is now guarded with #ifndef, so it is only defined when the binding did not, keeping the build working with both newer and older cbindgen (the min supported is 0.20.0; the commit-check job uses 0.24.3, which does not emit the macro). Validated by building detect-bytemath.o both with the macro present (newer cbindgen) and absent (older cbindgen) and running the bytemath unit tests (19 passed).
  • Commit 2 (the actual fix, Ticket Next/20221203/v1 #8237): detect: fail thread init on keyword ctx error. ThreadCtxDoInit ignored the return of DetectEngineThreadCtxInitKeywords, so a failing per-thread keyword init (for example DetectFilemagicThreadInit) left a partially initialized keyword context array and the detect thread ran with indeterminate results. The failure is now propagated so the callers abort thread init and clean up, with a unit test that fails without the fix and passes with it.

ssam18 added 2 commits June 9, 2026 16:55
Newer cbindgen (>= 0.29.3) exports the Rust DETECT_BYTEMATH_ENDIAN_DEFAULT
constant into rust-bindings.h as a macro, which collides under -Werror with
the macro defined under UNITTESTS in detect-bytemath.c and breaks the build.
Guard the C definition with ifndef so it is only defined when the binding did
not, keeping the build working with older cbindgen that does not emit it.
DetectEngineThreadCtxInitKeywords returns TM_ECODE_FAILED when a per-thread keyword init fails (for example DetectFilemagicThreadInit),
but ThreadCtxDoInit discarded that result and still returned OK. The detect thread then ran with a partially initialized keyword context
array, producing indeterminate results. Propagate the failure so the callers abort thread init and clean up.

Add a unit test that registers a keyword whose thread init fails and verifies that DetectEngineThreadCtxInit reports the failure.
Ticket: OISF#8237

@victorjulien victorjulien left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We fixed the cbindgen issue in a different way. Could you rebase this PR without the cbindgen fix and submit a new PR?

@ssam18

ssam18 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Done — rebased on current main without the cbindgen commit and submitted as #15630. Closing this one.

@ssam18 ssam18 closed this Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants